示例#1
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()));
}
示例#2
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));
}
示例#3
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()));
}
示例#4
0
JSString* errorDescriptionForValue(ExecState* exec, JSValue v)
{
    if (v.isString())
        return jsNontrivialString(exec, makeString('"',  asString(v)->value(exec), '"'));
    if (v.isSymbol())
        return jsNontrivialString(exec, asSymbol(v)->descriptiveString());
    if (v.isObject()) {
        CallData callData;
        JSObject* object = asObject(v);
        if (object->methodTable()->getCallData(object, callData) != CallType::None)
            return exec->vm().smallStrings.functionString();
        return jsString(exec, JSObject::calculatedClassName(object));
    }
    return v.toString(exec);
}
示例#5
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));
}
示例#6
0
bool GenericExpression::eqv(const GenericExpression &other) const
{
	{
		const SymbolExpression *symA = asSymbol();
		const SymbolExpression *symB = other.asSymbol();

		if (symA && symB)
		{
			return *symA == *symB;
		}
	}

	{
		const IntegerExpression *intA = asInteger();
		const IntegerExpression *intB = other.asInteger();

		if (intA && intB)
		{
			return intA->value() == intB->value();
		}
	}
	
	{
		const CharacterExpression *charA = asCharacter();
		const CharacterExpression *charB = other.asCharacter();

		if (charA && charB)
		{
			return charA->value() == charB->value();
		}
	}

	if (isEmptyList() && other.isEmptyList()) 
	{
		return true;
	}

	if (isUnspecified() && other.isUnspecified()) 
	{
		return true;
	}

	return false;
}
示例#7
0
JSC::JSInternalPromise* ScriptModuleLoader::resolve(JSC::JSGlobalObject* jsGlobalObject, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleNameValue, JSC::JSValue importerModuleKey, JSC::JSValue)
{
    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject);
    auto& jsPromise = *JSC::JSInternalPromiseDeferred::create(exec, &globalObject);
    auto promise = DeferredPromise::create(globalObject, jsPromise);

    // We use a Symbol as a special purpose; It means this module is an inline module.
    // So there is no correct URL to retrieve the module source code. If the module name
    // value is a Symbol, it is used directly as a module key.
    if (moduleNameValue.isSymbol()) {
        promise->resolve<IDLAny>(toJS(exec, &globalObject, asSymbol(moduleNameValue)->privateName()));
        return jsPromise.promise();
    }

    // https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier

    if (!moduleNameValue.isString()) {
        promise->reject(TypeError, ASCIILiteral("Module specifier is not Symbol or String."));
        return jsPromise.promise();
    }

    String specifier = asString(moduleNameValue)->value(exec);

    // 1. Apply the URL parser to specifier. If the result is not failure, return the result.
    URL absoluteURL(URL(), specifier);
    if (absoluteURL.isValid()) {
        promise->resolve<IDLDOMString>(absoluteURL.string());
        return jsPromise.promise();
    }

    // 2. If specifier does not start with the character U+002F SOLIDUS (/), the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./),
    //    or the three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS (../), return failure and abort these steps.
    if (!specifier.startsWith('/') && !specifier.startsWith("./") && !specifier.startsWith("../")) {
        promise->reject(TypeError, ASCIILiteral("Module specifier does not start with \"/\", \"./\", or \"../\"."));
        return jsPromise.promise();
    }

    // 3. Return the result of applying the URL parser to specifier with script's base URL as the base URL.

    URL completedURL;

    if (isRootModule(importerModuleKey))
        completedURL = m_document.completeURL(specifier);
    else if (importerModuleKey.isString()) {
        URL importerModuleRequestURL(URL(), asString(importerModuleKey)->value(exec));
        if (!importerModuleRequestURL.isValid()) {
            promise->reject(TypeError, ASCIILiteral("Importer module key is an invalid URL."));
            return jsPromise.promise();
        }

        URL importerModuleResponseURL = m_requestURLToResponseURLMap.get(importerModuleRequestURL);
        if (!importerModuleResponseURL.isValid()) {
            promise->reject(TypeError, ASCIILiteral("Importer module has an invalid response URL."));
            return jsPromise.promise();
        }

        completedURL = m_document.completeURL(specifier, importerModuleResponseURL);
    } else {
        promise->reject(TypeError, ASCIILiteral("Importer module key is not Symbol or String."));
        return jsPromise.promise();
    }

    if (!completedURL.isValid()) {
        promise->reject(TypeError, ASCIILiteral("Module name constructs an invalid URL."));
        return jsPromise.promise();
    }

    promise->resolve<IDLDOMString>(completedURL.string());
    return jsPromise.promise();
}