| Index: Source/bindings/v8/V8LazyEventListener.cpp
|
| diff --git a/Source/bindings/v8/V8LazyEventListener.cpp b/Source/bindings/v8/V8LazyEventListener.cpp
|
| index bd02cb77ca0d2be08ad4caf2972ef722a53c6587..fac7e7b0f701f5cc7e98659f831d4e0975fc6300 100644
|
| --- a/Source/bindings/v8/V8LazyEventListener.cpp
|
| +++ b/Source/bindings/v8/V8LazyEventListener.cpp
|
| @@ -53,7 +53,7 @@
|
| namespace WebCore {
|
|
|
| V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const AtomicString& eventParameterName, const String& code, const String sourceURL, const TextPosition& position, Node* node, v8::Isolate* isolate)
|
| - : V8AbstractEventListener(true, DOMWrapperWorld::mainWorld(), isolate)
|
| + : V8AbstractEventListener(true, isolate)
|
| , m_functionName(functionName)
|
| , m_eventParameterName(eventParameterName)
|
| , m_code(code)
|
| @@ -64,14 +64,14 @@ V8LazyEventListener::V8LazyEventListener(const AtomicString& functionName, const
|
| }
|
|
|
| template<typename T>
|
| -v8::Handle<v8::Object> toObjectWrapper(T* domObject, v8::Isolate* isolate)
|
| +v8::Handle<v8::Object> toObjectWrapper(T* domObject, ScriptState* scriptState)
|
| {
|
| if (!domObject)
|
| - return v8::Object::New(isolate);
|
| - v8::Handle<v8::Value> value = toV8(domObject, v8::Handle<v8::Object>(), isolate);
|
| + return v8::Object::New(scriptState->isolate());
|
| + v8::Handle<v8::Value> value = toV8(domObject, scriptState->context()->Global(), scriptState->isolate());
|
| if (value.IsEmpty())
|
| - return v8::Object::New(isolate);
|
| - return v8::Local<v8::Object>::New(isolate, value.As<v8::Object>());
|
| + return v8::Object::New(scriptState->isolate());
|
| + return v8::Local<v8::Object>::New(scriptState->isolate(), value.As<v8::Object>());
|
| }
|
|
|
| v8::Local<v8::Value> V8LazyEventListener::callListenerFunction(ExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
|
| @@ -81,7 +81,7 @@ v8::Local<v8::Value> V8LazyEventListener::callListenerFunction(ExecutionContext*
|
| return v8::Local<v8::Value>();
|
|
|
| v8::Local<v8::Function> handlerFunction = listenerObject.As<v8::Function>();
|
| - v8::Local<v8::Object> receiver = getReceiverObject(context, event);
|
| + v8::Local<v8::Object> receiver = getReceiverObject(event);
|
| if (handlerFunction.IsEmpty() || receiver.IsEmpty())
|
| return v8::Local<v8::Value>();
|
|
|
| @@ -108,6 +108,19 @@ static void V8LazyEventListenerToString(const v8::FunctionCallbackInfo<v8::Value
|
| v8SetReturnValue(info, V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::toStringString(info.GetIsolate())));
|
| }
|
|
|
| +void V8LazyEventListener::handleEvent(ExecutionContext* context, Event* event)
|
| +{
|
| + v8::HandleScope handleScope(toIsolate(context));
|
| + // V8LazyEventListener doesn't know the associated context when created.
|
| + // Thus we lazily get the associated context and set a ScriptState on V8AbstractEventListener.
|
| + v8::Local<v8::Context> v8Context = toV8Context(context, world());
|
| + if (v8Context.IsEmpty())
|
| + return;
|
| + setScriptState(ScriptState::from(v8Context));
|
| +
|
| + V8AbstractEventListener::handleEvent(context, event);
|
| +}
|
| +
|
| void V8LazyEventListener::prepareListenerObject(ExecutionContext* context)
|
| {
|
| if (context->isDocument() && !toDocument(context)->allowInlineEventHandlers(m_node, this, m_sourceURL, m_position.m_line)) {
|
| @@ -120,17 +133,15 @@ void V8LazyEventListener::prepareListenerObject(ExecutionContext* context)
|
|
|
| ASSERT(context->isDocument());
|
|
|
| - v8::Isolate* isolate = toIsolate(context);
|
| - v8::HandleScope handleScope(isolate);
|
| -
|
| - // Use the outer scope to hold context.
|
| + v8::HandleScope handleScope(toIsolate(context));
|
| + // V8LazyEventListener doesn't know the associated context when created.
|
| + // Thus we lazily get the associated context and set a ScriptState on V8AbstractEventListener.
|
| v8::Local<v8::Context> v8Context = toV8Context(context, world());
|
| - // Bail out if we cannot get the context.
|
| if (v8Context.IsEmpty())
|
| return;
|
| + setScriptState(ScriptState::from(v8Context));
|
|
|
| - v8::Context::Scope scope(v8Context);
|
| -
|
| + ScriptState::Scope scope(scriptState());
|
| String listenerSource = InspectorInstrumentation::preprocessEventListener(toDocument(context)->frame(), m_code, m_sourceURL, m_functionName);
|
|
|
| // FIXME: Remove the following 'with' hack.
|
| @@ -159,9 +170,9 @@ void V8LazyEventListener::prepareListenerObject(ExecutionContext* context)
|
| "};"
|
| "}}}})";
|
|
|
| - v8::Handle<v8::String> codeExternalString = v8String(isolate, code);
|
| + v8::Handle<v8::String> codeExternalString = v8String(isolate(), code);
|
|
|
| - v8::Local<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(codeExternalString, isolate, m_sourceURL, m_position);
|
| + v8::Local<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(codeExternalString, isolate(), m_sourceURL, m_position);
|
| if (result.IsEmpty())
|
| return;
|
|
|
| @@ -173,22 +184,22 @@ void V8LazyEventListener::prepareListenerObject(ExecutionContext* context)
|
| if (m_node && m_node->isHTMLElement())
|
| formElement = toHTMLElement(m_node)->formOwner();
|
|
|
| - v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node, isolate);
|
| - v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formElement, isolate);
|
| - v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ? m_node->ownerDocument() : 0, isolate);
|
| + v8::Handle<v8::Object> nodeWrapper = toObjectWrapper<Node>(m_node, scriptState());
|
| + v8::Handle<v8::Object> formWrapper = toObjectWrapper<HTMLFormElement>(formElement, scriptState());
|
| + v8::Handle<v8::Object> documentWrapper = toObjectWrapper<Document>(m_node ? m_node->ownerDocument() : 0, scriptState());
|
|
|
| - v8::Local<v8::Object> thisObject = v8::Object::New(isolate);
|
| + v8::Local<v8::Object> thisObject = v8::Object::New(isolate());
|
| if (thisObject.IsEmpty())
|
| return;
|
| - if (!thisObject->ForceSet(v8::Integer::New(isolate, 0), nodeWrapper))
|
| + if (!thisObject->ForceSet(v8::Integer::New(isolate(), 0), nodeWrapper))
|
| return;
|
| - if (!thisObject->ForceSet(v8::Integer::New(isolate, 1), formWrapper))
|
| + if (!thisObject->ForceSet(v8::Integer::New(isolate(), 1), formWrapper))
|
| return;
|
| - if (!thisObject->ForceSet(v8::Integer::New(isolate, 2), documentWrapper))
|
| + if (!thisObject->ForceSet(v8::Integer::New(isolate(), 2), documentWrapper))
|
| return;
|
|
|
| // FIXME: Remove this code when we stop doing the 'with' hack above.
|
| - v8::Local<v8::Value> innerValue = V8ScriptRunner::callInternalFunction(intermediateFunction, thisObject, 0, 0, isolate);
|
| + v8::Local<v8::Value> innerValue = V8ScriptRunner::callInternalFunction(intermediateFunction, thisObject, 0, 0, isolate());
|
| if (innerValue.IsEmpty() || !innerValue->IsFunction())
|
| return;
|
|
|
| @@ -202,12 +213,12 @@ void V8LazyEventListener::prepareListenerObject(ExecutionContext* context)
|
| // source returned (sometimes a RegExp is applied as well) for some
|
| // other use. That fails miserably if the actual wrapper source is
|
| // returned.
|
| - v8::Local<v8::Function> toStringFunction = v8::Function::New(isolate, V8LazyEventListenerToString);
|
| + v8::Local<v8::Function> toStringFunction = v8::Function::New(isolate(), V8LazyEventListenerToString);
|
| ASSERT(!toStringFunction.IsEmpty());
|
| String toStringString = "function " + m_functionName + "(" + m_eventParameterName + ") {\n " + m_code + "\n}";
|
| - V8HiddenValue::setHiddenValue(isolate, wrappedFunction, V8HiddenValue::toStringString(isolate), v8String(isolate, toStringString));
|
| - wrappedFunction->Set(v8AtomicString(isolate, "toString"), toStringFunction);
|
| - wrappedFunction->SetName(v8String(isolate, m_functionName));
|
| + V8HiddenValue::setHiddenValue(isolate(), wrappedFunction, V8HiddenValue::toStringString(isolate()), v8String(isolate(), toStringString));
|
| + wrappedFunction->Set(v8AtomicString(isolate(), "toString"), toStringFunction);
|
| + wrappedFunction->SetName(v8String(isolate(), m_functionName));
|
|
|
| // FIXME: Remove the following comment-outs.
|
| // See https://bugs.webkit.org/show_bug.cgi?id=85152 for more details.
|
|
|