Ejemplo n.º 1
0
v8::Handle<v8::Value> toV8(WorkerContext* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);

    WorkerContextExecutionProxy* proxy = impl->script()->proxy();
    if (!proxy)
        return v8NullWithCheck(isolate);

    v8::Handle<v8::Object> global = proxy->context()->Global();
    ASSERT(!global.IsEmpty());
    return global;
}
Ejemplo n.º 2
0
v8::Handle<v8::Value> toV8(WorkerContext* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    // Notice that we explicitly ignore creationContext because the WorkerContext is its own creationContext.

    if (!impl)
        return v8NullWithCheck(isolate);

    WorkerContextExecutionProxy* proxy = impl->script()->proxy();
    if (!proxy)
        return v8NullWithCheck(isolate);

    v8::Handle<v8::Object> global = proxy->context()->Global();
    ASSERT(!global.IsEmpty());
    return global;
}
Ejemplo n.º 3
0
v8::Handle<v8::Value> toV8(CSSRule* impl, v8::Handle<v8::Context> creationContext, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    switch (impl->type()) {
    case CSSRule::UNKNOWN_RULE:
        // CSSUnknownRule.idl is explicitly excluded as it doesn't add anything
        // over CSSRule.idl (see WebCore.gyp/WebCore.gyp: 'bindings_idl_files').
        // -> Use the base class wrapper here.
        return V8CSSRule::wrap(impl, creationContext, isolate);
    case CSSRule::STYLE_RULE:
        return toV8(static_cast<CSSStyleRule*>(impl), creationContext, isolate);
    case CSSRule::CHARSET_RULE:
        return toV8(static_cast<CSSCharsetRule*>(impl), creationContext, isolate);
    case CSSRule::IMPORT_RULE:
        return toV8(static_cast<CSSImportRule*>(impl), creationContext, isolate);
    case CSSRule::MEDIA_RULE:
        return toV8(static_cast<CSSMediaRule*>(impl), creationContext, isolate);
    case CSSRule::FONT_FACE_RULE:
        return toV8(static_cast<CSSFontFaceRule*>(impl), creationContext, isolate);
    case CSSRule::PAGE_RULE:
        return toV8(static_cast<CSSPageRule*>(impl), creationContext, isolate);
    case CSSRule::WEBKIT_KEYFRAME_RULE:
        return toV8(static_cast<WebKitCSSKeyframeRule*>(impl), creationContext, isolate);
    case CSSRule::WEBKIT_KEYFRAMES_RULE:
        return toV8(static_cast<WebKitCSSKeyframesRule*>(impl), creationContext, isolate);
    case CSSRule::WEBKIT_REGION_RULE:
        return toV8(static_cast<WebKitCSSRegionRule*>(impl), creationContext, isolate);
    }
    return V8CSSRule::wrap(impl, creationContext, isolate);
}
v8::Handle<v8::Value> toV8(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    // Notice that we explicitly ignore creationContext because the DOMWindow is its own creationContext.

    if (!window)
        return v8NullWithCheck(isolate);
    // Initializes environment of a frame, and return the global object
    // of the frame.
    Frame* frame = window->frame();
    if (!frame)
        return v8Undefined();

    // Special case: Because of executeScriptInIsolatedWorld() one DOMWindow can have
    // multiple contexts and multiple global objects associated with it. When
    // code running in one of those contexts accesses the window object, we
    // want to return the global object associated with that context, not
    // necessarily the first global object associated with that DOMWindow.
    v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent();
    v8::Handle<v8::Object> currentGlobal = currentContext->Global();
    v8::Handle<v8::Object> windowWrapper = currentGlobal->FindInstanceInPrototypeChain(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate)));
    if (!windowWrapper.IsEmpty()) {
        if (V8Window::toNative(windowWrapper) == window)
            return currentGlobal;
    }

    // Otherwise, return the global object associated with this frame.
    v8::Handle<v8::Context> context = frame->script()->currentWorldContext();
    if (context.IsEmpty())
        return v8Undefined();

    v8::Handle<v8::Object> global = context->Global();
    ASSERT(!global.IsEmpty());
    return global;
}
Ejemplo n.º 5
0
v8::Handle<v8::Value> toV8(IDBKey* key, v8::Isolate* isolate)
{
    if (!key)
        return v8NullWithCheck(isolate);

    switch (key->type()) {
    case IDBKey::InvalidType:
    case IDBKey::MinType:
        ASSERT_NOT_REACHED();
        return v8::Undefined();
    case IDBKey::NumberType:
        return v8::Number::New(key->number());
    case IDBKey::StringType:
        return v8String(key->string(), isolate);
    case IDBKey::DateType:
        return v8::Date::New(key->date());
    case IDBKey::ArrayType:
        {
            v8::Local<v8::Array> array = v8::Array::New(key->array().size());
            for (size_t i = 0; i < key->array().size(); ++i)
                array->Set(i, toV8(key->array()[i].get(), isolate));
            return array;
        }
    }

    ASSERT_NOT_REACHED();
    return v8::Undefined();
}
Ejemplo n.º 6
0
v8::Handle<v8::Value> toV8(StyleSheet* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    if (impl->isCSSStyleSheet())
        return toV8(static_cast<CSSStyleSheet*>(impl), creationContext, isolate);
    return V8StyleSheet::wrap(impl, creationContext, isolate);
}
Ejemplo n.º 7
0
v8::Handle<v8::Value> toV8(Uint16Array* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    v8::Handle<v8::Object> wrapper = V8Uint16Array::wrap(impl, isolate);
    if (!wrapper.IsEmpty())
        wrapper->SetIndexedPropertiesToExternalArrayData(impl->baseAddress(), v8::kExternalUnsignedShortArray, impl->length());
    return wrapper;
}
Ejemplo n.º 8
0
v8::Handle<v8::Value> toV8(Blob* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);

    if (impl->isFile())
        return toV8(toFile(impl), isolate);

    return V8Blob::wrap(impl, isolate);
}
Ejemplo n.º 9
0
// A JS object of type EventTarget is limited to a small number of possible classes.
v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* target, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!target)
        return v8NullWithCheck(isolate);

    AtomicString desiredInterface = target->interfaceName();
    DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)

    ASSERT_NOT_REACHED();
    return v8Undefined();
}
Ejemplo n.º 10
0
v8::Handle<v8::Value> toV8(Entry* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);

    if (impl->isFile())
        return toV8(static_cast<FileEntry*>(impl), isolate);

    ASSERT(impl->isDirectory());
    return toV8(static_cast<DirectoryEntry*>(impl), isolate);
}
Ejemplo n.º 11
0
v8::Handle<v8::Value> toV8(EventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);

    AtomicString desiredInterface = impl->interfaceName();
    DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_WRAP_WITH_INTERFACE)

    ASSERT_NOT_REACHED();
    return v8Undefined();
}
Ejemplo n.º 12
0
v8::Handle<v8::Value> toV8(IDBAny* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);

    switch (impl->type()) {
    case IDBAny::UndefinedType:
        return v8::Undefined();
    case IDBAny::NullType:
        return v8NullWithCheck(isolate);
    case IDBAny::DOMStringListType:
        return toV8(impl->domStringList(), creationContext, isolate);
    case IDBAny::IDBCursorType:
        return toV8(impl->idbCursor(), creationContext, isolate);
    case IDBAny::IDBCursorWithValueType:
        return toV8(impl->idbCursorWithValue(), creationContext, isolate);
    case IDBAny::IDBDatabaseType:
        return toV8(impl->idbDatabase(), creationContext, isolate);
    case IDBAny::IDBFactoryType:
        return toV8(impl->idbFactory(), creationContext, isolate);
    case IDBAny::IDBIndexType:
        return toV8(impl->idbIndex(), creationContext, isolate);
    case IDBAny::IDBObjectStoreType:
        return toV8(impl->idbObjectStore(), creationContext, isolate);
    case IDBAny::IDBTransactionType:
        return toV8(impl->idbTransaction(), creationContext, isolate);
    case IDBAny::ScriptValueType:
        return impl->scriptValue().v8Value();
    case IDBAny::StringType:
        return v8String(impl->string(), isolate);
    case IDBAny::IntegerType:
        return v8::Number::New(impl->integer());
    case IDBAny::KeyPathType:
        return toV8(impl->keyPath(), creationContext, isolate);
    }

    ASSERT_NOT_REACHED();
    return v8::Undefined();
}
Ejemplo n.º 13
0
v8::Handle<v8::Value> toV8(DOMStringMap* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    v8::Handle<v8::Object> wrapper = V8DOMStringMap::wrap(impl, isolate);
    // Add a hidden reference from the element to the DOMStringMap.
    Element* element = impl->element();
    if (!wrapper.IsEmpty() && element) {
        v8::Handle<v8::Value> elementValue = toV8(element, isolate);
        if (!elementValue.IsEmpty() && elementValue->IsObject())
            elementValue.As<v8::Object>()->SetHiddenValue(V8HiddenPropertyName::domStringMap(), wrapper);
    }
    return wrapper;
}
Ejemplo n.º 14
0
static v8::Handle<v8::Value> toV8(const IDBKeyPath& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    switch (value.type()) {
    case IDBKeyPath::NullType:
        return v8NullWithCheck(isolate);
    case IDBKeyPath::StringType:
        return v8String(value.string(), isolate);
    case IDBKeyPath::ArrayType:
        RefPtr<DOMStringList> keyPaths = DOMStringList::create();
        for (Vector<String>::const_iterator it = value.array().begin(); it != value.array().end(); ++it)
            keyPaths->append(*it);
        return toV8(keyPaths.release(), creationContext, isolate);
    }
    ASSERT_NOT_REACHED();
    return v8::Undefined();
}
Ejemplo n.º 15
0
v8::Handle<v8::Value> toV8(ScriptProfile* impl, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    v8::Local<v8::Function> function = V8ScriptProfile::GetTemplate()->GetFunction();
    if (function.IsEmpty()) {
        // Return if allocation failed.
        return v8Undefined();
    }
    v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
    if (instance.IsEmpty()) {
        // Avoid setting the wrapper if allocation failed.
        return v8Undefined();
    }
    impl->ref();
    V8DOMWrapper::setDOMWrapper(instance, &V8ScriptProfile::info, impl);
    return instance;
}
Ejemplo n.º 16
0
v8::Handle<v8::Value> toV8(SVGElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    return createV8SVGWrapper(impl, creationContext, isolate);
}
Ejemplo n.º 17
0
v8::Handle<v8::Value> toV8(HTMLElement* impl, v8::Isolate* isolate, bool forceNewObject)
{
    if (!impl)
        return v8NullWithCheck(isolate);
    return createV8HTMLWrapper(impl, isolate, forceNewObject);
}