Commit e4ae0871 authored by atotic's avatar atotic Committed by Commit bot

Pass ResizeObserver as 'this' to callback

I had to implement a custom callback dispatch handler.
Used MutationObserver code as a template.

Added a test case.

BUG=641353

Review-Url: https://codereview.chromium.org/2303893003
Cr-Commit-Position: refs/heads/master@{#417464}
parent ac2e7371
......@@ -164,6 +164,31 @@ function test6() {
return promise;
}
function test7() {
let harnessTest = async_test("test7: callback.this");
let resolvePromise;
let ro = new ResizeObserver( function(entries, obs) {
let callbackThis = this;
resolvePromise();
harnessTest.step(() => {
assert_equals(callbackThis, ro, "callback.this is ResizeObserver");
assert_equals(obs, ro, "2nd argument is ResizeObserver");
ro.disconnect();
// every reference to RO must be null before test completes
// to avoid triggering test leak-detection
ro = null;
callbackThis = null;
obs = null;
harnessTest.done();
});
}
);
ro.observe(t1);
return new Promise( (resolve, reject) => {
resolvePromise = resolve;
});
}
let guard = async_test('guard');
test0()
.then(() => { return test1(); })
......@@ -172,6 +197,7 @@ test0()
.then(() => { return test4(); })
.then(() => { return test5(); })
.then(() => { return test6(); })
.then(() => { return test7(); })
.then(() => { guard.done(); });
</script>
......@@ -189,6 +189,7 @@ bindings_core_v8_files =
"core/v8/V8PersistentValueVector.h",
"core/v8/V8PrivateProperty.cpp",
"core/v8/V8PrivateProperty.h",
"core/v8/V8ResizeObserverCallbackCustom.cpp",
"core/v8/V8ScriptRunner.cpp",
"core/v8/V8ScriptRunner.h",
"core/v8/V8StringResource.cpp",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "bindings/core/v8/V8ResizeObserverCallback.h"
#include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8ResizeObserver.h"
#include "bindings/core/v8/V8ResizeObserverEntry.h"
#include "core/dom/ExecutionContext.h"
namespace blink {
void V8ResizeObserverCallback::handleEvent(const HeapVector<Member<ResizeObserverEntry>>& entries, ResizeObserver* observer)
{
if (!canInvokeCallback())
return;
v8::Isolate* isolate = m_scriptState->isolate();
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
if (m_callback.isEmpty())
return;
v8::Local<v8::Value> observerHandle = toV8(observer, m_scriptState->context()->Global(), m_scriptState->isolate());
if (!observerHandle->IsObject())
return;
v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(observerHandle);
v8::Local<v8::Value> entriesHandle = toV8(entries, m_scriptState->context()->Global(), m_scriptState->isolate());
if (entriesHandle.IsEmpty())
return;
v8::Local<v8::Value> argv[] = { entriesHandle, observerHandle };
v8::TryCatch exceptionCatcher(m_scriptState->isolate());
exceptionCatcher.SetVerbose(true);
V8ScriptRunner::callFunction(m_callback.newLocal(isolate), getExecutionContext(), thisObject, WTF_ARRAY_LENGTH(argv), argv, isolate);
}
} // namespace blink
......@@ -3,5 +3,5 @@
// found in the LICENSE file.
callback interface ResizeObserverCallback {
void handleEvent(sequence<ResizeObserverEntry> entries, ResizeObserver observer);
[Custom] void handleEvent(sequence<ResizeObserverEntry> entries, ResizeObserver observer);
};
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