diff options
author | Kristian Monsen <kristianm@google.com> | 2010-07-30 10:46:49 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-08-04 13:01:34 +0100 |
commit | 0617145a89917ae7735fe1c9538688ab9a577df5 (patch) | |
tree | 56206078694427c37ed7bdf27eb5221398b833c0 /WebCore/bindings/js | |
parent | ef1adcdfc805d4d13103f6f15cc5b4d96828a60f (diff) | |
download | external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.zip external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.gz external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.bz2 |
Merge WebKit at r64264 : Initial merge by git.
Change-Id: Ic42bef02efef8217a0f84c47176a9c617c28d1f1
Diffstat (limited to 'WebCore/bindings/js')
-rw-r--r-- | WebCore/bindings/js/JSDatabaseCustom.cpp | 23 | ||||
-rw-r--r-- | WebCore/bindings/js/JSDatabaseSyncCustom.cpp | 15 | ||||
-rw-r--r-- | WebCore/bindings/js/JSHTMLAppletElementCustom.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/js/JSHTMLObjectElementCustom.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp | 4 | ||||
-rw-r--r-- | WebCore/bindings/js/JSPluginElementFunctions.cpp | 66 | ||||
-rw-r--r-- | WebCore/bindings/js/JSPluginElementFunctions.h | 5 | ||||
-rw-r--r-- | WebCore/bindings/js/ScriptObject.cpp | 9 | ||||
-rw-r--r-- | WebCore/bindings/js/ScriptObject.h | 2 | ||||
-rw-r--r-- | WebCore/bindings/js/ScriptValue.cpp | 59 | ||||
-rw-r--r-- | WebCore/bindings/js/ScriptValue.h | 5 | ||||
-rw-r--r-- | WebCore/bindings/js/SerializedScriptValue.cpp | 11 |
13 files changed, 149 insertions, 62 deletions
diff --git a/WebCore/bindings/js/JSDatabaseCustom.cpp b/WebCore/bindings/js/JSDatabaseCustom.cpp index 26f9db7..6733320 100644 --- a/WebCore/bindings/js/JSDatabaseCustom.cpp +++ b/WebCore/bindings/js/JSDatabaseCustom.cpp @@ -57,17 +57,20 @@ JSValue JSDatabase::changeVersion(ExecState* exec) if (exec->hadException()) return jsUndefined(); - JSObject* object = exec->argument(2).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } + RefPtr<SQLTransactionCallback> callback; + if (exec->argumentCount() > 2 && !exec->argument(2).isNull()) { + JSObject* object = exec->argument(2).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } - RefPtr<SQLTransactionCallback> callback(JSSQLTransactionCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject()))); + callback = JSSQLTransactionCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); + } RefPtr<SQLTransactionErrorCallback> errorCallback; - if (!exec->argument(3).isNull()) { - object = exec->argument(3).getObject(); + if (exec->argumentCount() > 3 && !exec->argument(3).isNull()) { + JSObject* object = exec->argument(3).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); @@ -77,8 +80,8 @@ JSValue JSDatabase::changeVersion(ExecState* exec) } RefPtr<VoidCallback> successCallback; - if (!exec->argument(4).isNull()) { - object = exec->argument(4).getObject(); + if (exec->argumentCount() > 4 && !exec->argument(4).isNull()) { + JSObject* object = exec->argument(4).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); diff --git a/WebCore/bindings/js/JSDatabaseSyncCustom.cpp b/WebCore/bindings/js/JSDatabaseSyncCustom.cpp index 79eb376..f929658 100644 --- a/WebCore/bindings/js/JSDatabaseSyncCustom.cpp +++ b/WebCore/bindings/js/JSDatabaseSyncCustom.cpp @@ -52,14 +52,17 @@ JSValue JSDatabaseSync::changeVersion(ExecState* exec) if (exec->hadException()) return jsUndefined(); - JSObject* object = exec->argument(2).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); + RefPtr<SQLTransactionSyncCallback> callback; + if (exec->argumentCount() > 2 && !exec->argument(2).isNull()) { + JSObject* object = exec->argument(2).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + callback = JSSQLTransactionSyncCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); } - RefPtr<SQLTransactionSyncCallback> callback(JSSQLTransactionSyncCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject()))); - ExceptionCode ec = 0; m_impl->changeVersion(oldVersion, newVersion, callback.release(), ec); setDOMException(exec, ec); diff --git a/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp b/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp index 40d20cf..2bff01a 100644 --- a/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp +++ b/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp @@ -45,12 +45,12 @@ bool JSHTMLAppletElement::getOwnPropertyDescriptorDelegate(ExecState* exec, cons bool JSHTMLAppletElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { - return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); } CallType JSHTMLAppletElement::getCallData(CallData& callData) { - return runtimeObjectGetCallData(impl(), callData); + return runtimeObjectGetCallData(this, callData); } } // namespace WebCore diff --git a/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp b/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp index b9f8c12..72e695b 100644 --- a/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp +++ b/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp @@ -45,12 +45,12 @@ bool JSHTMLEmbedElement::getOwnPropertyDescriptorDelegate(ExecState* exec, const bool JSHTMLEmbedElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { - return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); } CallType JSHTMLEmbedElement::getCallData(CallData& callData) { - return runtimeObjectGetCallData(impl(), callData); + return runtimeObjectGetCallData(this, callData); } } // namespace WebCore diff --git a/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp b/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp index 68c9e59..c87b932 100644 --- a/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp +++ b/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp @@ -45,12 +45,12 @@ bool JSHTMLObjectElement::getOwnPropertyDescriptorDelegate(ExecState* exec, cons bool JSHTMLObjectElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) { - return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); } CallType JSHTMLObjectElement::getCallData(CallData& callData) { - return runtimeObjectGetCallData(impl(), callData); + return runtimeObjectGetCallData(this, callData); } } // namespace WebCore diff --git a/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp b/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp index c119adf..b724f50 100644 --- a/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp +++ b/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp @@ -92,7 +92,9 @@ JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec) JSValue label = item->get(exec, Identifier(exec, "label")); JSValue id = item->get(exec, Identifier(exec, "id")); if (label.isUndefined() || id.isUndefined()) - items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String())); + items.append(new ContextMenuItem(SeparatorType, + ContextMenuItemCustomTagNoAction, + String())); else { ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec)); items.append(new ContextMenuItem(ActionType, typedId, ustringToString(label.toString(exec)))); diff --git a/WebCore/bindings/js/JSPluginElementFunctions.cpp b/WebCore/bindings/js/JSPluginElementFunctions.cpp index 7cc2e65..cf43e91 100644 --- a/WebCore/bindings/js/JSPluginElementFunctions.cpp +++ b/WebCore/bindings/js/JSPluginElementFunctions.cpp @@ -24,7 +24,7 @@ #include "HTMLNames.h" #include "HTMLPlugInElement.h" #include "JSHTMLElement.h" -#include "runtime_object.h" +#include "PluginViewBase.h" using namespace JSC; @@ -49,30 +49,50 @@ Instance* pluginInstance(Node* node) return instance; } -static RuntimeObject* getRuntimeObject(ExecState* exec, Node* node) +JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement) { - Instance* instance = pluginInstance(node); - if (!instance) + HTMLElement* element = jsHTMLElement->impl(); + if (!(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag))) return 0; + + HTMLPlugInElement* pluginElement = static_cast<HTMLPlugInElement*>(element); + + // First, see if we can ask the plug-in view for its script object. + if (Widget* pluginWidget = pluginElement->pluginWidget()) { + if (pluginWidget->isPluginViewBase()) { + PluginViewBase* pluginViewBase = static_cast<PluginViewBase*>(pluginWidget); + if (JSObject* scriptObject = pluginViewBase->scriptObject(exec, jsHTMLElement->globalObject())) + return scriptObject; + } + } + + // Otherwise, fall back to getting the object from the instance. + + // The plugin element holds an owning reference, so we don't have to. + Instance* instance = pluginElement->getInstance().get(); + if (!instance || !instance->rootObject()) + return 0; + return instance->createRuntimeObject(exec); } - + JSValue runtimeObjectPropertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) { - JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slotBase)); - HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl()); - RuntimeObject* runtimeObject = getRuntimeObject(exec, element); - if (!runtimeObject) + JSHTMLElement* element = static_cast<JSHTMLElement*>(asObject(slotBase)); + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) return jsUndefined(); - return runtimeObject->get(exec, propertyName); + + return scriptObject->get(exec, propertyName); } bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* element) { - RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl()); - if (!runtimeObject) + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) return false; - if (!runtimeObject->hasProperty(exec, propertyName)) + + if (!scriptObject->hasProperty(exec, propertyName)) return false; slot.setCustom(element, runtimeObjectPropertyGetter); return true; @@ -80,10 +100,10 @@ bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& pr bool runtimeObjectCustomGetOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, JSHTMLElement* element) { - RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl()); - if (!runtimeObject) + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) return false; - if (!runtimeObject->hasProperty(exec, propertyName)) + if (!scriptObject->hasProperty(exec, propertyName)) return false; PropertySlot slot; slot.setCustom(element, runtimeObjectPropertyGetter); @@ -94,14 +114,14 @@ bool runtimeObjectCustomGetOwnPropertyDescriptor(ExecState* exec, const Identifi return true; } -bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, HTMLElement* element, PutPropertySlot& slot) +bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, JSHTMLElement* element, PutPropertySlot& slot) { - RuntimeObject* runtimeObject = getRuntimeObject(exec, element); - if (!runtimeObject) + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) return 0; - if (!runtimeObject->hasProperty(exec, propertyName)) + if (!scriptObject->hasProperty(exec, propertyName)) return false; - runtimeObject->put(exec, propertyName, value, slot); + scriptObject->put(exec, propertyName, value, slot); return true; } @@ -114,9 +134,9 @@ static EncodedJSValue JSC_HOST_CALL callPlugin(ExecState* exec) return JSValue::encode(result); } -CallType runtimeObjectGetCallData(HTMLElement* element, CallData& callData) +CallType runtimeObjectGetCallData(JSHTMLElement* element, CallData& callData) { - Instance* instance = pluginInstance(element); + Instance* instance = pluginInstance(element->impl()); if (!instance || !instance->supportsInvokeDefaultMethod()) return CallTypeNone; callData.native.function = callPlugin; diff --git a/WebCore/bindings/js/JSPluginElementFunctions.h b/WebCore/bindings/js/JSPluginElementFunctions.h index 736ace9..15af59a 100644 --- a/WebCore/bindings/js/JSPluginElementFunctions.h +++ b/WebCore/bindings/js/JSPluginElementFunctions.h @@ -36,12 +36,13 @@ namespace WebCore { // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement. JSC::Bindings::Instance* pluginInstance(Node*); + JSC::JSObject* pluginScriptObject(JSC::ExecState* exec, JSHTMLElement* jsHTMLElement); JSC::JSValue runtimeObjectPropertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&); bool runtimeObjectCustomGetOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&, JSHTMLElement*); bool runtimeObjectCustomGetOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&, JSHTMLElement*); - bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, HTMLElement*, JSC::PutPropertySlot&); - JSC::CallType runtimeObjectGetCallData(HTMLElement*, JSC::CallData&); + bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSHTMLElement*, JSC::PutPropertySlot&); + JSC::CallType runtimeObjectGetCallData(JSHTMLElement*, JSC::CallData&); } // namespace WebCore diff --git a/WebCore/bindings/js/ScriptObject.cpp b/WebCore/bindings/js/ScriptObject.cpp index 16b9f01..de397f7 100644 --- a/WebCore/bindings/js/ScriptObject.cpp +++ b/WebCore/bindings/js/ScriptObject.cpp @@ -37,7 +37,6 @@ #if ENABLE(INSPECTOR) #include "JSInjectedScriptHost.h" -#include "JSInspectorBackend.h" #include "JSInspectorFrontendHost.h" #endif @@ -158,14 +157,6 @@ bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const S } #if ENABLE(INSPECTOR) -bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, InspectorBackend* value) -{ - JSLock lock(SilenceAssertionsOnly); - JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); - globalObject->putDirect(Identifier(scriptState, name), toJS(scriptState, globalObject, value)); - return handleException(scriptState); -} - bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, InspectorFrontendHost* value) { JSLock lock(SilenceAssertionsOnly); diff --git a/WebCore/bindings/js/ScriptObject.h b/WebCore/bindings/js/ScriptObject.h index 0c993e1..9880976 100644 --- a/WebCore/bindings/js/ScriptObject.h +++ b/WebCore/bindings/js/ScriptObject.h @@ -39,7 +39,6 @@ namespace WebCore { class InjectedScriptHost; - class InspectorBackend; class InspectorFrontendHost; class ScriptObject : public ScriptValue { @@ -70,7 +69,6 @@ namespace WebCore { public: static bool set(ScriptState*, const char* name, const ScriptObject&); #if ENABLE(INSPECTOR) - static bool set(ScriptState*, const char* name, InspectorBackend*); static bool set(ScriptState*, const char* name, InspectorFrontendHost*); static bool set(ScriptState*, const char* name, InjectedScriptHost*); #endif diff --git a/WebCore/bindings/js/ScriptValue.cpp b/WebCore/bindings/js/ScriptValue.cpp index a52024d..abc31e2 100644 --- a/WebCore/bindings/js/ScriptValue.cpp +++ b/WebCore/bindings/js/ScriptValue.cpp @@ -29,6 +29,7 @@ #include "config.h" #include "ScriptValue.h" +#include "InspectorValues.h" #include "SerializedScriptValue.h" #include <JavaScriptCore/APICast.h> @@ -93,4 +94,62 @@ ScriptValue ScriptValue::deserialize(ScriptState* scriptState, SerializedScriptV return ScriptValue(value->deserialize(scriptState, scriptState->lexicalGlobalObject())); } +#if ENABLE(INSPECTOR) +static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value) +{ + if (!value) { + ASSERT_NOT_REACHED(); + return 0; + } + if (value.isNull() || value.isUndefined()) + return InspectorValue::null(); + if (value.isBoolean()) + return InspectorBasicValue::create(value.getBoolean()); + if (value.isNumber()) + return InspectorBasicValue::create(value.uncheckedGetNumber()); + if (value.isString()) { + UString s = value.getString(scriptState); + return InspectorString::create(String(s.data(), s.size())); + } + if (value.isObject()) { + if (isJSArray(&scriptState->globalData(), value)) { + RefPtr<InspectorArray> inspectorArray = InspectorArray::create(); + JSArray* array = asArray(value); + unsigned length = array->length(); + for (unsigned i = 0; i < length; i++) { + JSValue element = array->getIndex(i); + RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element); + if (!elementValue) { + ASSERT_NOT_REACHED(); + elementValue = InspectorValue::null(); + } + inspectorArray->push(elementValue); + } + return inspectorArray; + } + RefPtr<InspectorObject> inspectorObject = InspectorObject::create(); + JSObject* object = value.getObject(); + PropertyNameArray propertyNames(scriptState); + object->getOwnPropertyNames(scriptState, propertyNames); + for (size_t i = 0; i < propertyNames.size(); i++) { + const Identifier& name = propertyNames[i]; + JSValue propertyValue = object->get(scriptState, name); + RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue); + if (!inspectorValue) { + ASSERT_NOT_REACHED(); + inspectorValue = InspectorValue::null(); + } + inspectorObject->set(String(name.data(), name.size()), inspectorValue); + } + return inspectorObject; + } + return 0; +} + +PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const +{ + return jsToInspectorValue(scriptState, m_value.get()); +} +#endif // ENABLE(INSPECTOR) + } // namespace WebCore diff --git a/WebCore/bindings/js/ScriptValue.h b/WebCore/bindings/js/ScriptValue.h index f4f9c68..b170fcf 100644 --- a/WebCore/bindings/js/ScriptValue.h +++ b/WebCore/bindings/js/ScriptValue.h @@ -40,6 +40,7 @@ namespace WebCore { +class InspectorValue; class SerializedScriptValue; class ScriptValue { @@ -61,6 +62,10 @@ public: static ScriptValue undefined() { return ScriptValue(JSC::jsUndefined()); } +#if ENABLE(INSPECTOR) + PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const; +#endif + private: JSC::ProtectedJSValue m_value; }; diff --git a/WebCore/bindings/js/SerializedScriptValue.cpp b/WebCore/bindings/js/SerializedScriptValue.cpp index 90f8d7c..6d6fa21 100644 --- a/WebCore/bindings/js/SerializedScriptValue.cpp +++ b/WebCore/bindings/js/SerializedScriptValue.cpp @@ -736,18 +736,23 @@ struct DeserializingTreeWalker : public BaseWalker { return jsNumber(m_exec, value.asDouble()); case SerializedScriptValueData::DateType: return new (m_exec) DateInstance(m_exec, m_globalObject->dateStructure(), value.asDouble()); - case SerializedScriptValueData::FileType: + case SerializedScriptValueData::FileType: { if (!m_isDOMGlobalObject) return jsNull(); - return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), File::create(value.asString().crossThreadString())); + ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject())->scriptExecutionContext(); + ASSERT(scriptExecutionContext); + return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), File::create(scriptExecutionContext, value.asString().crossThreadString())); + } case SerializedScriptValueData::FileListType: { if (!m_isDOMGlobalObject) return jsNull(); RefPtr<FileList> result = FileList::create(); SerializedFileList* serializedFileList = value.asFileList(); unsigned length = serializedFileList->length(); + ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject())->scriptExecutionContext(); + ASSERT(scriptExecutionContext); for (unsigned i = 0; i < length; i++) - result->append(File::create(serializedFileList->item(i))); + result->append(File::create(scriptExecutionContext, serializedFileList->item(i))); return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get()); } case SerializedScriptValueData::ImageDataType: { |