| Differences between
and this patch
- a/Source/WebCore/ChangeLog +24 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-03-21  Adam Klein  <adamk@chromium.org>
2
3
        "this" argument for MutationCallbacks should be the MutationObserver
4
        https://bugs.webkit.org/show_bug.cgi?id=81712
5
6
        Reviewed by Adam Barth.
7
8
        Test: fast/mutation/callback-arguments.html
9
10
        * bindings/js/JSCallbackData.cpp:
11
        (WebCore::JSCallbackData::invokeCallback): Add an overload that takes
12
        an explicit this argument and have the old method call the new one.
13
        * bindings/js/JSCallbackData.h:
14
        (JSCallbackData):
15
        * bindings/js/JSMutationCallbackCustom.cpp:
16
        (WebCore::JSMutationCallback::handleEvent): Call the new overload.
17
        * bindings/v8/custom/V8CustomVoidCallback.cpp:
18
        (WebCore::invokeCallback): Add an overload that takes an explicit this
19
        argument and have the old method call the new one.
20
        * bindings/v8/custom/V8CustomVoidCallback.h:
21
        (WebCore):
22
        * bindings/v8/custom/V8MutationCallbackCustom.cpp:
23
        (WebCore::V8MutationCallback::handleEvent): Call the new overload.
24
1
2012-03-21  Mark Pilgrim  <pilgrim@chromium.org>
25
2012-03-21  Mark Pilgrim  <pilgrim@chromium.org>
2
26
3
        Realphabetize about webaudio move
27
        Realphabetize about webaudio move
- a/Source/WebCore/bindings/js/JSCallbackData.cpp -5 / +11 lines
Lines 45-50 void JSCallbackData::deleteData(void* context) a/Source/WebCore/bindings/js/JSCallbackData.cpp_sec1
45
JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException)
45
JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException)
46
{
46
{
47
    ASSERT(callback());
47
    ASSERT(callback());
48
    return invokeCallback(callback(), args, raisedException);
49
}
50
51
JSValue JSCallbackData::invokeCallback(JSValue thisValue, MarkedArgumentBuffer& args, bool* raisedException)
52
{
53
    ASSERT(callback());
48
    ASSERT(globalObject());
54
    ASSERT(globalObject());
49
55
50
    ExecState* exec = globalObject()->globalExec();
56
    ExecState* exec = globalObject()->globalExec();
Lines 58-64 JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedE a/Source/WebCore/bindings/js/JSCallbackData.cpp_sec2
58
        if (callType == CallTypeNone)
64
        if (callType == CallTypeNone)
59
            return JSValue();
65
            return JSValue();
60
    }
66
    }
61
    
67
62
    ScriptExecutionContext* context = globalObject()->scriptExecutionContext();
68
    ScriptExecutionContext* context = globalObject()->scriptExecutionContext();
63
    // We will fail to get the context if the frame has been detached.
69
    // We will fail to get the context if the frame has been detached.
64
    if (!context)
70
    if (!context)
Lines 69-76 JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedE a/Source/WebCore/bindings/js/JSCallbackData.cpp_sec3
69
75
70
    bool contextIsDocument = context->isDocument();
76
    bool contextIsDocument = context->isDocument();
71
    JSValue result = contextIsDocument
77
    JSValue result = contextIsDocument
72
        ? JSMainThreadExecState::call(exec, function, callType, callData, callback(), args)
78
        ? JSMainThreadExecState::call(exec, function, callType, callData, thisValue, args)
73
        : JSC::call(exec, function, callType, callData, callback(), args);
79
        : JSC::call(exec, function, callType, callData, thisValue, args);
74
80
75
    InspectorInstrumentation::didCallFunction(cookie);
81
    InspectorInstrumentation::didCallFunction(cookie);
76
    globalObject()->globalData().timeoutChecker.stop();
82
    globalObject()->globalData().timeoutChecker.stop();
Lines 84-91 JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedE a/Source/WebCore/bindings/js/JSCallbackData.cpp_sec4
84
            *raisedException = true;
90
            *raisedException = true;
85
        return result;
91
        return result;
86
    }
92
    }
87
    
93
88
    return result;
94
    return result;
89
}
95
}
90
    
96
91
} // namespace WebCore
97
} // namespace WebCore
- a/Source/WebCore/bindings/js/JSCallbackData.h +1 lines
Lines 65-70 public: a/Source/WebCore/bindings/js/JSCallbackData.h_sec1
65
    JSDOMGlobalObject* globalObject() { return m_globalObject.get(); }
65
    JSDOMGlobalObject* globalObject() { return m_globalObject.get(); }
66
    
66
    
67
    JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
67
    JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
68
    JSC::JSValue invokeCallback(JSC::JSValue thisValue, JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
68
69
69
private:
70
private:
70
    JSC::Strong<JSC::JSObject> m_callback;
71
    JSC::Strong<JSC::JSObject> m_callback;
- a/Source/WebCore/bindings/js/JSMutationCallbackCustom.cpp -2 / +4 lines
Lines 58-69 bool JSMutationCallback::handleEvent(MutationRecordArray* mutations, WebKitMutat a/Source/WebCore/bindings/js/JSMutationCallbackCustom.cpp_sec1
58
    for (size_t i = 0; i < mutations->size(); ++i)
58
    for (size_t i = 0; i < mutations->size(); ++i)
59
        mutationList.append(toJS(exec, m_data->globalObject(), mutations->at(i).get()));
59
        mutationList.append(toJS(exec, m_data->globalObject(), mutations->at(i).get()));
60
60
61
    JSValue jsObserver = toJS(exec, m_data->globalObject(), observer);
62
61
    MarkedArgumentBuffer args;
63
    MarkedArgumentBuffer args;
62
    args.append(constructArray(exec, m_data->globalObject(), mutationList));
64
    args.append(constructArray(exec, m_data->globalObject(), mutationList));
63
    args.append(toJS(exec, m_data->globalObject(), observer));
65
    args.append(jsObserver);
64
66
65
    bool raisedException = false;
67
    bool raisedException = false;
66
    m_data->invokeCallback(args, &raisedException);
68
    m_data->invokeCallback(jsObserver, args, &raisedException);
67
    return !raisedException;
69
    return !raisedException;
68
}
70
}
69
71
- a/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp -2 / +5 lines
Lines 65-70 void V8CustomVoidCallback::handleEvent() a/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp_sec1
65
65
66
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
66
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
67
{
67
{
68
    return invokeCallback(callback, v8::Context::GetCurrent()->Global(), argc, argv, callbackReturnValue, scriptExecutionContext);
69
}
70
71
bool invokeCallback(v8::Persistent<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
72
{
68
    v8::TryCatch exceptionCatcher;
73
    v8::TryCatch exceptionCatcher;
69
    exceptionCatcher.SetVerbose(true);
74
    exceptionCatcher.SetVerbose(true);
70
75
Lines 81-88 bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8 a/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp_sec2
81
    if (callbackFunction.IsEmpty())
86
    if (callbackFunction.IsEmpty())
82
        return false;
87
        return false;
83
88
84
    v8::Handle<v8::Object> thisObject = v8::Context::GetCurrent()->Global();
85
86
    Frame* frame = scriptExecutionContext && scriptExecutionContext->isDocument() ? static_cast<Document*>(scriptExecutionContext)->frame() : 0;
89
    Frame* frame = scriptExecutionContext && scriptExecutionContext->isDocument() ? static_cast<Document*>(scriptExecutionContext)->frame() : 0;
87
    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(frame, callbackFunction, thisObject, argc, argv);
90
    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(frame, callbackFunction, thisObject, argc, argv);
88
91
- a/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.h -1 / +2 lines
Lines 61-67 private: a/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.h_sec1
61
};
61
};
62
62
63
// Returns false if callback failed (null, wrong type, or threw exception).
63
// Returns false if callback failed (null, wrong type, or threw exception).
64
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext);
64
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
65
bool invokeCallback(v8::Persistent<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
65
66
66
} // namespace WebCore
67
} // namespace WebCore
67
68
- a/Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp -1 / +4 lines
Lines 75-87 bool V8MutationCallback::handleEvent(MutationRecordArray* mutations, WebKitMutat a/Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp_sec1
75
        return true;
75
        return true;
76
    }
76
    }
77
77
78
    if (!observerHandle->IsObject())
79
        return true;
80
78
    v8::Handle<v8::Value> argv[] = {
81
    v8::Handle<v8::Value> argv[] = {
79
        mutationsArray,
82
        mutationsArray,
80
        observerHandle
83
        observerHandle
81
    };
84
    };
82
85
83
    bool callbackReturnValue = false;
86
    bool callbackReturnValue = false;
84
    return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext());
87
    return !invokeCallback(m_callback, v8::Handle<v8::Object>::Cast(observerHandle), 2, argv, callbackReturnValue, scriptExecutionContext());
85
}
88
}
86
89
87
} // namespace WebCore
90
} // namespace WebCore
- a/LayoutTests/ChangeLog +14 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2012-03-21  Adam Klein  <adamk@chromium.org>
2
3
        "this" argument for MutationCallbacks should be the MutationObserver
4
        https://bugs.webkit.org/show_bug.cgi?id=81712
5
6
        Reviewed by Adam Barth.
7
8
        Merged new test with existing second-argument test.
9
10
        * fast/mutation/callback-arguments-expected.txt: Added.
11
        * fast/mutation/callback-arguments.html: Added.
12
        * fast/mutation/callback-second-argument-expected.txt: Removed.
13
        * fast/mutation/callback-second-argument.html: Removed.
14
1
2012-03-21  Stephen Chenney  <schenney@chromium.org>
15
2012-03-21  Stephen Chenney  <schenney@chromium.org>
2
16
3
        SVG layout leaves objects still needing layout
17
        SVG layout leaves objects still needing layout
- a/LayoutTests/fast/mutation/callback-arguments-expected.txt +11 lines
Line 0 a/LayoutTests/fast/mutation/callback-arguments-expected.txt_sec1
1
Verifies that MutationObserver is passed to the callback as expected.
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS thisArgument is mutationObserver
7
PASS argument2 is mutationObserver
8
PASS successfullyParsed is true
9
10
TEST COMPLETE
11
- a/LayoutTests/fast/mutation/callback-arguments.html +21 lines
Line 0 a/LayoutTests/fast/mutation/callback-arguments.html_sec1
1
<!DOCTYPE html>
2
<body>
3
<script src="../js/resources/js-test-pre.js"></script>
4
<script>
5
window.jsTestIsAsync = true;
6
description('Verifies that MutationObserver is passed to the callback as expected.');
7
8
function mutationCallback(mutations, observer) {
9
    window.thisArgument = this;
10
    window.argument2 = observer;
11
    shouldBe('thisArgument', 'mutationObserver');
12
    shouldBe('argument2', 'mutationObserver');
13
    finishJSTest();
14
}
15
var mutationObserver = new WebKitMutationObserver(mutationCallback);
16
var div = document.createElement('div');
17
mutationObserver.observe(div, {attributes: true});
18
div.setAttribute('foo', 'bar');
19
</script>
20
<script src="../js/resources/js-test-post.js"></script>
21
</body>
- a/LayoutTests/fast/mutation/callback-second-argument-expected.txt -1 lines
Line 1 a/LayoutTests/fast/mutation/callback-second-argument-expected.txt_sec1
1
PASSED: Second argument is mutationObserver
- a/LayoutTests/fast/mutation/callback-second-argument.html -20 lines
Lines 1-20 a/LayoutTests/fast/mutation/callback-second-argument.html_sec1
1
<!DOCTYPE html>
2
<body>
3
<script>
4
if (window.layoutTestController) {
5
    layoutTestController.dumpAsText();
6
    layoutTestController.waitUntilDone();
7
}
8
9
function mutationCallback(mutations, observer) {
10
    mutations[0].addedNodes[0].textContent = (observer === mutationObserver)
11
        ? 'PASSED: Second argument is mutationObserver'
12
        : 'FAILED: Second argument is not mutationObserver';
13
    if (window.layoutTestController)
14
        layoutTestController.notifyDone();
15
}
16
var mutationObserver = new WebKitMutationObserver(mutationCallback);
17
mutationObserver.observe(document.body, {childList: true});
18
document.body.appendChild(document.createTextNode('FAILED'));
19
</script>
20
</body>

Return to Bug 81712