Пример #1
0
JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v)
{
    if (v.isUndefined())
        return vm.smallStrings.undefinedString();
    if (v.isBoolean())
        return vm.smallStrings.booleanString();
    if (v.isNumber())
        return vm.smallStrings.numberString();
    if (v.isString())
        return vm.smallStrings.stringString();
    if (v.isSymbol())
        return vm.smallStrings.symbolString();
    if (v.isObject()) {
        JSObject* object = asObject(v);
        // Return "undefined" for objects that should be treated
        // as null when doing comparisons.
        if (object->structure(vm)->masqueradesAsUndefined(globalObject))
            return vm.smallStrings.undefinedString();
        if (object->type() == JSFunctionType)
            return vm.smallStrings.functionString();
        if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) {
            CallData callData;
            JSObject* object = asObject(v);
            if (object->methodTable(vm)->getCallData(object, callData) != CallTypeNone)
                return vm.smallStrings.functionString();
        }
    }
    return vm.smallStrings.objectString();
}
Пример #2
0
JSValue JSInjectedScriptHost::subtype(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return jsUndefined();

    JSValue value = exec->uncheckedArgument(0);
    if (value.isString())
        return exec->vm().smallStrings.stringString();
    if (value.isBoolean())
        return exec->vm().smallStrings.booleanString();
    if (value.isNumber())
        return exec->vm().smallStrings.numberString();
    if (value.isSymbol())
        return exec->vm().smallStrings.symbolString();

    JSObject* object = asObject(value);
    if (object) {
        if (object->isErrorInstance())
            return jsNontrivialString(exec, ASCIILiteral("error"));

        // Consider class constructor functions class objects.
        JSFunction* function = jsDynamicCast<JSFunction*>(value);
        if (function && function->isClassConstructorFunction())
            return jsNontrivialString(exec, ASCIILiteral("class"));
    }

    if (value.inherits(JSArray::info()))
        return jsNontrivialString(exec, ASCIILiteral("array"));
    if (value.inherits(DirectArguments::info()) || value.inherits(ScopedArguments::info()))
        return jsNontrivialString(exec, ASCIILiteral("array"));

    if (value.inherits(DateInstance::info()))
        return jsNontrivialString(exec, ASCIILiteral("date"));
    if (value.inherits(RegExpObject::info()))
        return jsNontrivialString(exec, ASCIILiteral("regexp"));

    if (value.inherits(JSMap::info()))
        return jsNontrivialString(exec, ASCIILiteral("map"));
    if (value.inherits(JSSet::info()))
        return jsNontrivialString(exec, ASCIILiteral("set"));
    if (value.inherits(JSWeakMap::info()))
        return jsNontrivialString(exec, ASCIILiteral("weakmap"));
    if (value.inherits(JSWeakSet::info()))
        return jsNontrivialString(exec, ASCIILiteral("weakset"));

    if (value.inherits(JSArrayIterator::info())
        || value.inherits(JSMapIterator::info())
        || value.inherits(JSSetIterator::info())
        || value.inherits(JSStringIterator::info()))
        return jsNontrivialString(exec, ASCIILiteral("iterator"));

    if (value.inherits(JSInt8Array::info()) || value.inherits(JSInt16Array::info()) || value.inherits(JSInt32Array::info()))
        return jsNontrivialString(exec, ASCIILiteral("array"));
    if (value.inherits(JSUint8Array::info()) || value.inherits(JSUint16Array::info()) || value.inherits(JSUint32Array::info()))
        return jsNontrivialString(exec, ASCIILiteral("array"));
    if (value.inherits(JSFloat32Array::info()) || value.inherits(JSFloat64Array::info()))
        return jsNontrivialString(exec, ASCIILiteral("array"));

    return impl().subtype(exec, value);
}
Пример #3
0
RuntimeType runtimeTypeForValue(JSValue value)
{
    if (UNLIKELY(!value))
        return TypeNothing;

    if (value.isUndefined())
        return TypeUndefined;
    if (value.isNull())
        return TypeNull;
    if (value.isAnyInt())
        return TypeAnyInt;
    if (value.isNumber())
        return TypeNumber;
    if (value.isString())
        return TypeString;
    if (value.isBoolean())
        return TypeBoolean;
    if (value.isObject())
        return TypeObject;
    if (value.isFunction())
        return TypeFunction;
    if (value.isSymbol())
        return TypeSymbol;

    return TypeNothing;
}
Пример #4
0
static EncodedJSValue JSC_HOST_CALL callStringConstructor(ExecState* exec)
{
    if (!exec->argumentCount())
        return JSValue::encode(jsEmptyString(exec));
    JSValue argument = exec->uncheckedArgument(0);
    if (argument.isSymbol())
        return JSValue::encode(jsString(exec, asSymbol(argument)->descriptiveString()));
    return JSValue::encode(argument.toString(exec));
}
Пример #5
0
EncodedJSValue JSC_HOST_CALL symbolProtoFuncValueOf(ExecState* exec)
{
    JSValue thisValue = exec->thisValue();
    if (thisValue.isSymbol())
        return JSValue::encode(thisValue);

    if (!thisValue.isObject())
        return throwVMTypeError(exec);

    JSObject* thisObject = asObject(thisValue);
    if (!thisObject->inherits(SymbolObject::info()))
        return throwVMTypeError(exec);

    return JSValue::encode(jsCast<SymbolObject*>(thisObject)->internalValue());
}
Пример #6
0
EncodedJSValue JSC_HOST_CALL symbolConstructorKeyFor(ExecState* exec)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    JSValue symbolValue = exec->argument(0);
    if (!symbolValue.isSymbol())
        return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral(SymbolKeyForTypeError)));

    SymbolImpl& uid = asSymbol(symbolValue)->privateName().uid();
    if (!uid.symbolRegistry())
        return JSValue::encode(jsUndefined());

    ASSERT(uid.symbolRegistry() == &vm.symbolRegistry());
    return JSValue::encode(jsString(exec, &uid));
}
Пример #7
0
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);
    else {
        JSObject* thisObject = asObject(thisValue);
        if (!thisObject->inherits(SymbolObject::info()))
            return throwVMTypeError(exec);
        symbol = asSymbol(jsCast<SymbolObject*>(thisObject)->internalValue());
    }

    return JSValue::encode(jsNontrivialString(exec, symbol->descriptiveString()));
}
Пример #8
0
EncodedJSValue JSC_HOST_CALL symbolProtoFuncValueOf(ExecState* exec)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    JSValue thisValue = exec->thisValue();
    if (thisValue.isSymbol())
        return JSValue::encode(thisValue);

    if (!thisValue.isObject())
        return throwVMTypeError(exec, scope, SymbolValueOfTypeError);

    JSObject* thisObject = asObject(thisValue);
    if (!thisObject->inherits(vm, SymbolObject::info()))
        return throwVMTypeError(exec, scope, SymbolValueOfTypeError);

    return JSValue::encode(jsCast<SymbolObject*>(thisObject)->internalValue());
}
Пример #9
0
EncodedJSValue JSC_HOST_CALL symbolProtoFuncToString(ExecState* exec)
{
    VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    JSValue thisValue = exec->thisValue();
    Symbol* symbol = nullptr;
    if (thisValue.isSymbol())
        symbol = asSymbol(thisValue);
    else {
        if (!thisValue.isObject())
            return throwVMTypeError(exec, scope, SymbolToStringTypeError);
        JSObject* thisObject = asObject(thisValue);
        if (!thisObject->inherits(vm, SymbolObject::info()))
            return throwVMTypeError(exec, scope, SymbolToStringTypeError);
        symbol = asSymbol(jsCast<SymbolObject*>(thisObject)->internalValue());
    }

    return JSValue::encode(jsNontrivialString(exec, symbol->descriptiveString()));
}
Пример #10
0
static String printableModuleKey(ExecState* exec, JSValue key)
{
    if (key.isString() || key.isSymbol())
        return key.toPropertyKey(exec).impl();
    return exec->propertyNames().emptyIdentifier.impl();
}
Пример #11
0
void WASMModuleParser::parseGlobalSection(ExecState* exec)
{
    uint32_t numberOfInternalI32GlobalVariables;
    uint32_t numberOfInternalF32GlobalVariables;
    uint32_t numberOfInternalF64GlobalVariables;
    uint32_t numberOfImportedI32GlobalVariables;
    uint32_t numberOfImportedF32GlobalVariables;
    uint32_t numberOfImportedF64GlobalVariables;
    READ_COMPACT_UINT32_OR_FAIL(numberOfInternalI32GlobalVariables, "Cannot read the number of internal int32 global variables.");
    READ_COMPACT_UINT32_OR_FAIL(numberOfInternalF32GlobalVariables, "Cannot read the number of internal float32 global variables.");
    READ_COMPACT_UINT32_OR_FAIL(numberOfInternalF64GlobalVariables, "Cannot read the number of internal float64 global variables.");
    READ_COMPACT_UINT32_OR_FAIL(numberOfImportedI32GlobalVariables, "Cannot read the number of imported int32 global variables.");
    READ_COMPACT_UINT32_OR_FAIL(numberOfImportedF32GlobalVariables, "Cannot read the number of imported float32 global variables.");
    READ_COMPACT_UINT32_OR_FAIL(numberOfImportedF64GlobalVariables, "Cannot read the number of imported float64 global variables.");
    uint32_t numberOfGlobalVariables = numberOfInternalI32GlobalVariables + numberOfInternalF32GlobalVariables + numberOfInternalF64GlobalVariables +
        numberOfImportedI32GlobalVariables + numberOfImportedF32GlobalVariables + numberOfImportedF64GlobalVariables;

    Vector<WASMType>& globalVariableTypes = m_module->globalVariableTypes();
    globalVariableTypes.reserveInitialCapacity(numberOfGlobalVariables);
    Vector<JSWASMModule::GlobalVariable>& globalVariables = m_module->globalVariables();
    globalVariables.reserveInitialCapacity(numberOfGlobalVariables);
    for (uint32_t i = 0; i < numberOfInternalI32GlobalVariables; ++i) {
        globalVariableTypes.uncheckedAppend(WASMType::I32);
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0));
    }
    for (uint32_t i = 0; i < numberOfInternalF32GlobalVariables; ++i) {
        globalVariableTypes.uncheckedAppend(WASMType::F32);
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0f));
    }
    for (uint32_t i = 0; i < numberOfInternalF64GlobalVariables; ++i) {
        globalVariableTypes.uncheckedAppend(WASMType::F64);
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0));
    }
    for (uint32_t i = 0; i < numberOfImportedI32GlobalVariables; ++i) {
        String importName;
        READ_STRING_OR_FAIL(importName, "Cannot read the import name of an int32 global variable.");
        globalVariableTypes.uncheckedAppend(WASMType::I32);
        JSValue value;
        getImportedValue(exec, importName, value);
        PROPAGATE_ERROR();
        FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol.");
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toInt32(exec)));
    }
    for (uint32_t i = 0; i < numberOfImportedF32GlobalVariables; ++i) {
        String importName;
        READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float32 global variable.");
        globalVariableTypes.uncheckedAppend(WASMType::F32);
        JSValue value;
        getImportedValue(exec, importName, value);
        PROPAGATE_ERROR();
        FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol.");
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(static_cast<float>(value.toNumber(exec))));
    }
    for (uint32_t i = 0; i < numberOfImportedF64GlobalVariables; ++i) {
        String importName;
        READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float64 global variable.");
        globalVariableTypes.uncheckedAppend(WASMType::F64);
        JSValue value;
        getImportedValue(exec, importName, value);
        PROPAGATE_ERROR();
        FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol.");
        globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toNumber(exec)));
    }
}