52ReturnedValue SymbolCtor::method_for(
const FunctionObject *f,
const Value *,
const Value *argv,
int argc)
55 ScopedValue k(scope, argc ? argv[0] : Value::undefinedValue());
56 ScopedString key(scope, k->toString(scope.engine));
57 if (scope.hasException())
58 return Encode::undefined();
59 QString desc = QLatin1Char(
'@') + key->toQString();
60 return scope.engine->identifierTable->insertSymbol(desc)->asReturnedValue();
63ReturnedValue SymbolCtor::method_keyFor(
const FunctionObject *f,
const Value *,
const Value *argv,
int argc)
65 ExecutionEngine *e = f->engine();
66 if (!argc || !argv[0].isSymbol())
67 return e->throwTypeError(QLatin1String(
"Symbol.keyFor: Argument is not a symbol."));
68 const Symbol &arg =
static_cast<
const Symbol &>(argv[0]);
69 Heap::Symbol *s = e->identifierTable->symbolForId(arg.propertyKey());
70 Q_ASSERT(!s || s == arg.d());
72 return e->newString(arg.toQString().mid((1)))->asReturnedValue();
73 return Encode::undefined();
76void SymbolPrototype::init(ExecutionEngine *engine, Object *ctor)
80 ctor->defineReadonlyProperty(engine->id_prototype(), (v =
this));
81 ctor->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(0));
83 ctor->defineDefaultProperty(
QStringLiteral(
"for"), SymbolCtor::method_for, 1);
84 ctor->defineDefaultProperty(
QStringLiteral(
"keyFor"), SymbolCtor::method_keyFor, 1);
85 ctor->defineReadonlyProperty(
QStringLiteral(
"hasInstance"), *engine->symbol_hasInstance());
86 ctor->defineReadonlyProperty(
QStringLiteral(
"isConcatSpreadable"), *engine->symbol_isConcatSpreadable());
87 ctor->defineReadonlyProperty(
QStringLiteral(
"iterator"), *engine->symbol_iterator());
88 ctor->defineReadonlyProperty(
QStringLiteral(
"match"), *engine->symbol_match());
89 ctor->defineReadonlyProperty(
QStringLiteral(
"replace"), *engine->symbol_replace());
90 ctor->defineReadonlyProperty(
QStringLiteral(
"search"), *engine->symbol_search());
91 ctor->defineReadonlyProperty(
QStringLiteral(
"species"), *engine->symbol_species());
92 ctor->defineReadonlyProperty(
QStringLiteral(
"split"), *engine->symbol_split());
93 ctor->defineReadonlyProperty(
QStringLiteral(
"toPrimitive"), *engine->symbol_toPrimitive());
94 ctor->defineReadonlyProperty(
QStringLiteral(
"toStringTag"), *engine->symbol_toStringTag());
95 ctor->defineReadonlyProperty(
QStringLiteral(
"unscopables"), *engine->symbol_unscopables());
98 defineDefaultProperty(
QStringLiteral(
"toString"), method_toString);
100 defineDefaultProperty(engine->symbol_toPrimitive(), method_symbolToPrimitive, 1, Attr_ReadOnly_ButConfigurable);
103 defineReadonlyConfigurableProperty(engine->symbol_toStringTag(), v);
107ReturnedValue SymbolPrototype::method_toString(
const FunctionObject *f,
const Value *thisObject,
const Value *,
int)
110 Scoped<Symbol> s(scope, thisObject->as<Symbol>());
112 if (
const SymbolObject *o = thisObject->as<SymbolObject>())
115 return scope.engine->throwTypeError();
117 return scope.engine->newString(s->descriptiveString())->asReturnedValue();
120ReturnedValue SymbolPrototype::method_valueOf(
const FunctionObject *f,
const Value *thisObject,
const Value *,
int)
123 Scoped<Symbol> s(scope, thisObject->as<Symbol>());
125 if (
const SymbolObject *o = thisObject->as<SymbolObject>())
128 return scope.engine->throwTypeError();
130 return s->asReturnedValue();
133ReturnedValue SymbolPrototype::method_symbolToPrimitive(
const FunctionObject *f,
const Value *thisObject,
const Value *,
int)
135 if (thisObject->isSymbol())
136 return thisObject->asReturnedValue();
137 if (
const SymbolObject *o = thisObject->as<SymbolObject>())
138 return o->d()->symbol->asReturnedValue();
139 return f->engine()->throwTypeError();