Commit 4545d12b authored by xiang.long@intel.com's avatar xiang.long@intel.com

Fix V8 callback binding for "CallWith=ThisValue" attribute.

ThisValue should support "any" type other than "object".

BUG=382728

Review URL: https://codereview.chromium.org/330163004

git-svn-id: svn://svn.chromium.org/blink/trunk@176262 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3024a9f5
......@@ -82,5 +82,17 @@ test(function() {
assert_equals(headers.get(key), expectedMap[key]);
});
}, 'HeaderMap in ServiceWorkerGlobalScope');
// 'forEach()' with thisArg
var that = {}, saw_that;
headers = new HeaderMap;
headers.set('a', 'b');
headers.forEach(function() { saw_that = this; }, that);
assert_equals(saw_that, that, 'Passed thisArg should match');
headers.forEach(function() { 'use strict'; saw_that = this; }, 'abc');
assert_equals(saw_that, 'abc', 'Passed non-object thisArg should match');
headers.forEach(function() { saw_that = this; }, null);
assert_equals(saw_that, self, 'Passed null thisArg should be replaced with global object');
}, 'HeaderMap in ServiceWorkerGlobalScope');
......@@ -45,7 +45,6 @@ namespace WebCore {
CRASH();
{{return_default}};
}
ASSERT(thisHandle->IsObject());
{% endif %}
{% for argument in method.arguments %}
v8::Handle<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}};
......@@ -61,7 +60,7 @@ namespace WebCore {
v8::Handle<v8::Value> *argv = 0;
{% endif %}
{% set this_handle_parameter = 'v8::Handle<v8::Object>::Cast(thisHandle), ' if method.call_with_this_handle else '' %}
{% set this_handle_parameter = 'thisHandle, ' if method.call_with_this_handle else '' %}
{% if method.idl_type == 'boolean' %}
return invokeCallback(m_scriptState.get(), m_callback.newLocal(isolate), {{this_handle_parameter}}{{method.arguments | length}}, argv);
{% else %}{# void #}
......
......@@ -186,7 +186,6 @@ void V8TestCallbackInterface::callbackWithThisValueVoidMethodStringArg(ScriptVal
CRASH();
return;
}
ASSERT(thisHandle->IsObject());
v8::Handle<v8::Value> stringArgHandle = v8String(isolate, stringArg);
if (stringArgHandle.IsEmpty()) {
if (!isScriptControllerTerminating())
......@@ -195,7 +194,7 @@ void V8TestCallbackInterface::callbackWithThisValueVoidMethodStringArg(ScriptVal
}
v8::Handle<v8::Value> argv[] = { stringArgHandle };
invokeCallback(m_scriptState.get(), m_callback.newLocal(isolate), v8::Handle<v8::Object>::Cast(thisHandle), 1, argv);
invokeCallback(m_scriptState.get(), m_callback.newLocal(isolate), thisHandle, 1, argv);
}
void V8TestCallbackInterface::voidMethodWillBeGarbageCollectedSequenceArg(const WillBeHeapVector<RefPtrWillBeMember<TestInterfaceWillBeGarbageCollected> >& sequenceArg)
......
......@@ -41,11 +41,11 @@ bool invokeCallback(ScriptState* scriptState, v8::Local<v8::Function> callback,
return invokeCallback(scriptState, callback, scriptState->context()->Global(), argc, argv);
}
bool invokeCallback(ScriptState* scriptState, v8::Local<v8::Function> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[])
bool invokeCallback(ScriptState* scriptState, v8::Local<v8::Function> callback, v8::Handle<v8::Value> thisValue, int argc, v8::Handle<v8::Value> argv[])
{
v8::TryCatch exceptionCatcher;
exceptionCatcher.SetVerbose(true);
ScriptController::callFunction(scriptState->executionContext(), callback, thisObject, argc, argv, scriptState->isolate());
ScriptController::callFunction(scriptState->executionContext(), callback, thisValue, argc, argv, scriptState->isolate());
return !exceptionCatcher.HasCaught();
}
......
......@@ -42,7 +42,7 @@ class ExecutionContext;
// Returns false if the callback threw an exception, true otherwise.
bool invokeCallback(ScriptState*, v8::Local<v8::Function> callback, int argc, v8::Handle<v8::Value> argv[]);
bool invokeCallback(ScriptState*, v8::Local<v8::Function> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[]);
bool invokeCallback(ScriptState*, v8::Local<v8::Function> callback, v8::Handle<v8::Value> thisValue, int argc, v8::Handle<v8::Value> argv[]);
// FIXME: This file is used only by V8GeolocationCustom.cpp. Remove the custom binding and this file.
enum CallbackAllowedValueFlag {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment