SymbolPrototype.cpp [plain text]
#include "config.h"
#include "SymbolPrototype.h"
#include "Error.h"
#include "JSCInlines.h"
#include "JSString.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL symbolProtoFuncToString(ExecState*);
static EncodedJSValue JSC_HOST_CALL symbolProtoFuncValueOf(ExecState*);
}
#include "SymbolPrototype.lut.h"
namespace JSC {
const ClassInfo SymbolPrototype::s_info = { "Symbol", &Base::s_info, &symbolPrototypeTable, CREATE_METHOD_TABLE(SymbolPrototype) };
SymbolPrototype::SymbolPrototype(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
void SymbolPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(&vm, "Symbol"), DontEnum | ReadOnly);
ASSERT(inherits(info()));
JSC_NATIVE_FUNCTION(vm.propertyNames->toPrimitiveSymbol, symbolProtoFuncValueOf, DontEnum | ReadOnly, 1);
}
static const char* SymbolToStringTypeError = "Symbol.prototype.toString requires that |this| be a symbol or a symbol object";
static const char* SymbolValueOfTypeError = "Symbol.prototype.valueOf requires that |this| be a symbol or a symbol object";
EncodedJSValue JSC_HOST_CALL symbolProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
Symbol* symbol = nullptr;
if (thisValue.isSymbol())
symbol = asSymbol(thisValue);
else {
if (!thisValue.isObject())
return throwVMTypeError(exec, SymbolToStringTypeError);
JSObject* thisObject = asObject(thisValue);
if (!thisObject->inherits(SymbolObject::info()))
return throwVMTypeError(exec, SymbolToStringTypeError);
symbol = asSymbol(jsCast<SymbolObject*>(thisObject)->internalValue());
}
return JSValue::encode(jsNontrivialString(exec, symbol->descriptiveString()));
}
EncodedJSValue JSC_HOST_CALL symbolProtoFuncValueOf(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (thisValue.isSymbol())
return JSValue::encode(thisValue);
if (!thisValue.isObject())
return throwVMTypeError(exec, SymbolValueOfTypeError);
JSObject* thisObject = asObject(thisValue);
if (!thisObject->inherits(SymbolObject::info()))
return throwVMTypeError(exec, SymbolValueOfTypeError);
return JSValue::encode(jsCast<SymbolObject*>(thisObject)->internalValue());
}
}