예제 #1
0
JSC::JSValue ScriptModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue, JSC::JSValue)
{
    JSC::VM& vm = exec->vm();
    auto scope = DECLARE_THROW_SCOPE(vm);

    // FIXME: Currently, we only support JSModuleRecord.
    // Once the reflective part of the module loader is supported, we will handle arbitrary values.
    // https://whatwg.github.io/loader/#registry-prototype-provide
    auto* moduleRecord = jsDynamicDowncast<JSC::JSModuleRecord*>(moduleRecordValue);
    if (!moduleRecord)
        return JSC::jsUndefined();

    URL sourceURL;
    if (moduleKeyValue.isSymbol())
        sourceURL = m_document.url();
    else if (moduleKeyValue.isString())
        sourceURL = URL(URL(), asString(moduleKeyValue)->value(exec));
    else
        return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is not Symbol or String."));

    if (!sourceURL.isValid())
        return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is an invalid URL."));

    if (auto* frame = m_document.frame())
        return frame->script().evaluateModule(sourceURL, *moduleRecord);
    return JSC::jsUndefined();
}
예제 #2
0
String DragData::asURL(String* /*title*/) const
{
    JSC::JSLock lock(false);
    bool success;
    JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::URI_LIST_TYPE, success);
    if (success && data.isString())
        return String(ustringToString(data.toString(m_platformDragData->execState())));
    return String();
}
예제 #3
0
PassRefPtr<IDBKey> createIDBKeyFromValue(JSC::ExecState* exec, JSC::JSValue value)
{
    if (value.isNull())
        return IDBKey::create();
    if (value.isInt32())
        return IDBKey::create(value.toInt32(exec));
    if (value.isString())
        return IDBKey::create(ustringToString(value.toString(exec)));
    // FIXME: Implement dates.
    return 0;
}
예제 #4
0
파일: FontFace.cpp 프로젝트: eocanha/webkit
ExceptionOr<Ref<FontFace>> FontFace::create(JSC::ExecState& state, Document& document, const String& family, JSC::JSValue source, const Descriptors& descriptors)
{
    auto result = adoptRef(*new FontFace(document.fontSelector()));

    bool dataRequiresAsynchronousLoading = true;

    auto setFamilyResult = result->setFamily(family);
    if (setFamilyResult.hasException())
        return setFamilyResult.releaseException();

    if (source.isString()) {
        auto value = FontFace::parseString(source.getString(&state), CSSPropertySrc);
        if (!is<CSSValueList>(value.get()))
            return Exception { SYNTAX_ERR };
        CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false);
    } else if (auto arrayBufferView = toUnsharedArrayBufferView(source))
        dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
    else if (auto arrayBuffer = toUnsharedArrayBuffer(source)) {
        auto arrayBufferView = JSC::Uint8Array::create(arrayBuffer, 0, arrayBuffer->byteLength());
        dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
    }

    // These ternaries match the default strings inside the FontFaceDescriptors dictionary inside FontFace.idl.
    auto setStyleResult = result->setStyle(descriptors.style.isEmpty() ? ASCIILiteral("normal") : descriptors.style);
    if (setStyleResult.hasException())
        return setStyleResult.releaseException();
    auto setWeightResult = result->setWeight(descriptors.weight.isEmpty() ? ASCIILiteral("normal") : descriptors.weight);
    if (setWeightResult.hasException())
        return setWeightResult.releaseException();
    auto setStretchResult = result->setStretch(descriptors.stretch.isEmpty() ? ASCIILiteral("normal") : descriptors.stretch);
    if (setStretchResult.hasException())
        return setStretchResult.releaseException();
    auto setUnicodeRangeResult = result->setUnicodeRange(descriptors.unicodeRange.isEmpty() ? ASCIILiteral("U+0-10FFFF") : descriptors.unicodeRange);
    if (setUnicodeRangeResult.hasException())
        return setUnicodeRangeResult.releaseException();
    auto setVariantResult = result->setVariant(descriptors.variant.isEmpty() ? ASCIILiteral("normal") : descriptors.variant);
    if (setVariantResult.hasException())
        return setVariantResult.releaseException();
    auto setFeatureSettingsResult = result->setFeatureSettings(descriptors.featureSettings.isEmpty() ? ASCIILiteral("normal") : descriptors.featureSettings);
    if (setFeatureSettingsResult.hasException())
        return setFeatureSettingsResult.releaseException();

    if (!dataRequiresAsynchronousLoading) {
        result->backing().load();
        ASSERT(result->backing().status() == CSSFontFace::Status::Success);
    }

    return WTFMove(result);
}
예제 #5
0
JSType JSValueGetType(JSContextRef, JSValueRef value)
{
    JSC::JSValue* jsValue = toJS(value);
    if (jsValue->isUndefined())
        return kJSTypeUndefined;
    if (jsValue->isNull())
        return kJSTypeNull;
    if (jsValue->isBoolean())
        return kJSTypeBoolean;
    if (jsValue->isNumber())
        return kJSTypeNumber;
    if (jsValue->isString())
        return kJSTypeString;
    ASSERT(jsValue->isObject());
    return kJSTypeObject;
}
예제 #6
0
JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
{
    JSC::ExecState* exec = toJS(ctx);
    exec->globalData().heap.registerThread();
    JSC::JSLock lock(exec);

    JSC::JSValue jsValue = toJS(exec, value);

    if (jsValue.isUndefined())
        return kJSTypeUndefined;
    if (jsValue.isNull())
        return kJSTypeNull;
    if (jsValue.isBoolean())
        return kJSTypeBoolean;
    if (jsValue.isNumber())
        return kJSTypeNumber;
    if (jsValue.isString())
        return kJSTypeString;
    ASSERT(jsValue.isObject());
    return kJSTypeObject;
}
예제 #7
0
bool WebFrame::stringByEvaluatingJavaScriptInScriptWorld(WebScriptWorld* world, void* jsGlobalObject, const char* script, const char** evaluationResult)
{
    if (!world || !jsGlobalObject || !evaluationResult)
        return false;
    *evaluationResult = 0;

    Frame* coreFrame = core(this);
    JSObjectRef globalObjectRef = reinterpret_cast<JSObjectRef>(jsGlobalObject);
    String string = String(script);

    // Start off with some guess at a frame and a global object, we'll try to do better...!
    JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());

    // The global object is probably a shell object? - if so, we know how to use this!
    JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
    if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
        anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();

    // Get the frame from the global object we've settled on.
    Frame* frame = anyWorldGlobalObject->impl()->frame();
    ASSERT(frame->document());
    JSC::JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();

    if (!frame) // In case the script removed our frame from the page.
        return true;

    // This bizarre set of rules matches behavior from WebKit for Safari 2.0.
    // If you don't like it, use -[WebScriptObject evaluateWebScript:] or 
    // JSEvaluateScript instead, since they have less surprising semantics.
    if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
        return true;

    JSC::JSLock lock(JSC::SilenceAssertionsOnly);
    String resultString = ustringToString(result.toString(anyWorldGlobalObject->globalExec()));
    *evaluationResult = strdup(resultString.utf8().data());

    return true;
}
예제 #8
0
String DragData::asPlainText() const
{
    JSC::JSLock lock(false);
    bool success;
    JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::TEXT_TYPE, success);
    if (success && data.isString())
        return String(ustringToString(data.toString(m_platformDragData->execState())));

    Vector<String> filenames;
    asFilenames(filenames);
    if (!filenames.isEmpty()) {
        String result;
        for (unsigned int i=0; i<filenames.size(); i++)
            result.append(filenames[i] + "\n");
        return result;
    }

    String url(asURL(NULL));
    if (!url.isEmpty())
        return url;

    return String();
}
예제 #9
0
void DragData::asFilenames(Vector<String>& result) const
{
    bool success;
    JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::FILE_LIST_TYPE, success);
    JSC::ExecState *exec = m_platformDragData->execState();
    if (success && data.isObject()) {
        JSC::JSObject* filenameArray = data.toObject(exec);
        uint32_t length = filenameArray->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec);
        for (uint32_t i=0; i<length; i++) {
            JSC::JSValue fileValue = filenameArray->get(exec, i);
            if (fileValue.isObject()) {
                JSC::JSObject* file = fileValue.toObject(exec);
                JSC::JSValue pathValue = file->get(exec, JSC::Identifier(exec, "nativePath"));
                if (pathValue.isString()) {
                    String path = ustringToString(pathValue.toString(exec));
                    result.append(path);
                }
            }
        }
    }
    if (exec->hadException())
        exec->clearException();
}
예제 #10
0
JSC::JSValue JSModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue)
{
    // FIXME: Currently, we only support JSModuleRecord.
    // Once the reflective part of the module loader is supported, we will handle arbitrary values.
    // https://whatwg.github.io/loader/#registry-prototype-provide
    JSC::JSModuleRecord* moduleRecord = JSC::jsDynamicCast<JSC::JSModuleRecord*>(moduleRecordValue);
    if (!moduleRecord)
        return JSC::jsUndefined();

    URL sourceUrl;
    if (moduleKeyValue.isSymbol())
        sourceUrl = m_document.url();
    else if (moduleKeyValue.isString())
        sourceUrl = URL(URL(), asString(moduleKeyValue)->value(exec));
    else
        return JSC::throwTypeError(exec, ASCIILiteral("Module key is not Symbol or String."));

    if (!sourceUrl.isValid())
        return JSC::throwTypeError(exec, ASCIILiteral("Module key is an invalid URL."));

    // FIXME: Implement evaluating module code.

    return JSC::jsUndefined();
}