summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorager@google.com <ager@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 19:29:29 +0000
committerager@google.com <ager@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-07 19:29:29 +0000
commita0889edfabc7e231af01f6044f0d2d6c684c1493 (patch)
tree781ffe453ba68f173a626540dfa73e53a8fa9e96
parent6e4dea5b594cdd042b087ae4fc6343ab63d4af3c (diff)
downloadchromium_src-a0889edfabc7e231af01f6044f0d2d6c684c1493.zip
chromium_src-a0889edfabc7e231af01f6044f0d2d6c684c1493.tar.gz
chromium_src-a0889edfabc7e231af01f6044f0d2d6c684c1493.tar.bz2
Keep MessagePort wrappers alive for the life-time of the corresponding
MessageChannel. I create the MessagePort wrappers when a MessageChannel is constructed and put references to them in internal fields in the MessageChannel. This is a fix for http://code.google.com/p/chromium/issues/detail?id=4195 Review URL: http://codereview.chromium.org/9508 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5006 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/port/bindings/v8/v8_custom.cpp32
-rw-r--r--webkit/port/bindings/v8/v8_custom.h7
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp17
-rw-r--r--webkit/tools/layout_tests/test_lists/mac/tests_fixable.txt4
-rw-r--r--webkit/tools/layout_tests/test_lists/win/tests_fixable.txt4
5 files changed, 45 insertions, 19 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp
index 23a226d..c8b4743 100644
--- a/webkit/port/bindings/v8/v8_custom.cpp
+++ b/webkit/port/bindings/v8/v8_custom.cpp
@@ -262,9 +262,6 @@ CALLBACK_FUNC_DECL(DOMParserConstructor) {
DOMParser>(args);
}
-// TODO(mbelshe): merge this with the XHR Constructor.
-// The only difference is that this one takes an argument to its
-// create call, the XHR does not.
CALLBACK_FUNC_DECL(MessageChannelConstructor) {
INC_STATS(L"DOM.MessageChannel.Constructor");
if (!args.IsConstructCall()) {
@@ -282,11 +279,32 @@ CALLBACK_FUNC_DECL(MessageChannelConstructor) {
// Note: it's OK to let this RefPtr go out of scope because we also call
// SetDOMWrapper(), which effectively holds a reference to obj.
RefPtr<MessageChannel> obj = MessageChannel::create(document);
- V8Proxy::SetDOMWrapper(args.Holder(), V8ClassIndex::MESSAGECHANNEL,
- obj.get());
+
+ // Create wrappers for the two associated MessagePorts.
+ v8::Handle<v8::Value> port1_wrapper =
+ V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT,
+ static_cast<Peerable*>(obj->port1()));
+ v8::Handle<v8::Value> port2_wrapper =
+ V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT,
+ static_cast<Peerable*>(obj->port2()));
+
+ v8::Handle<v8::Object> wrapper_object = args.Holder();
+
+ // Setup the standard wrapper object internal fields.
+ V8Proxy::SetDOMWrapper(
+ wrapper_object, V8ClassIndex::MESSAGECHANNEL, obj.get());
V8Proxy::SetJSWrapperForDOMObject(
- obj.get(), v8::Persistent<v8::Object>::New(args.Holder()));
- return args.Holder();
+ obj.get(), v8::Persistent<v8::Object>::New(wrapper_object));
+
+ // Create references from the MessageChannel wrapper to the two
+ // MessagePort wrappers to make sure that the MessagePort wrappers
+ // stay alive as long as the MessageChannel wrapper is around.
+ wrapper_object->SetInternalField(kMessageChannelPort1Index, port1_wrapper);
+ wrapper_object->SetInternalField(kMessageChannelPort2Index, port2_wrapper);
+
+ // Return the wrapper object which will be the result of the call to
+ // new.
+ return wrapper_object;
}
diff --git a/webkit/port/bindings/v8/v8_custom.h b/webkit/port/bindings/v8/v8_custom.h
index 6ce3239..d3bee4c 100644
--- a/webkit/port/bindings/v8/v8_custom.h
+++ b/webkit/port/bindings/v8/v8_custom.h
@@ -54,6 +54,13 @@ class V8Custom {
static const int kXMLHttpRequestInternalFieldCount =
kDefaultWrapperInternalFieldCount + 1;
+ static const int kMessageChannelPort1Index =
+ kDefaultWrapperInternalFieldCount + 0;
+ static const int kMessageChannelPort2Index =
+ kDefaultWrapperInternalFieldCount + 1;
+ static const int kMessageChannelInternalFieldCount =
+ kDefaultWrapperInternalFieldCount + 2;
+
static const int kMessagePortRequestCacheIndex =
kDefaultWrapperInternalFieldCount + 0;
static const int kMessagePortInternalFieldCount =
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index eb6250a..0833a3b 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -1384,11 +1384,20 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
break;
}
- case V8ClassIndex::MESSAGECHANNEL:
- desc->SetCallHandler(USE_CALLBACK(MessageChannelConstructor));
- break;
+ case V8ClassIndex::MESSAGECHANNEL: {
+ // Reserve two more internal fields for referencing the port1
+ // and port2 wrappers. This ensures that the port wrappers are
+ // kept alive when the channel wrapper is.
+ desc->SetCallHandler(USE_CALLBACK(MessageChannelConstructor));
+ v8::Local<v8::ObjectTemplate> instance_template =
+ desc->InstanceTemplate();
+ instance_template->SetInternalFieldCount(
+ V8Custom::kMessageChannelInternalFieldCount);
+ break;
+ }
+
case V8ClassIndex::MESSAGEPORT: {
- // Reserve one more internal field for keeping event listeners.
+ // Reserve one more internal field for keeping event listeners.
v8::Local<v8::ObjectTemplate> instance_template =
desc->InstanceTemplate();
instance_template->SetInternalFieldCount(
diff --git a/webkit/tools/layout_tests/test_lists/mac/tests_fixable.txt b/webkit/tools/layout_tests/test_lists/mac/tests_fixable.txt
index f8508de..5bd754e 100644
--- a/webkit/tools/layout_tests/test_lists/mac/tests_fixable.txt
+++ b/webkit/tools/layout_tests/test_lists/mac/tests_fixable.txt
@@ -682,10 +682,6 @@ V8 # LayoutTests/fast/js/date-set-to-nan.html = FAIL
# http://crbug.com/2844
V8 # SKIP : LayoutTests/http/tests/appcache = TIMEOUT | FAIL
-# GC issue with MessageChannels.
-# http://code.google.com/p/chromium/issues/detail?id=4195
-V8 # LayoutTests/fast/events/message-channel-gc.html = PASS | FAIL
-
# Depends on postMessage in a way we don't support:
# http://code.google.com/p/chromium/issues/detail?id=2857
V8 # LayoutTests/http/tests/security/dataURL/xss-DENIED-to-data-url-sub-frame-uppercase.html = FAIL
diff --git a/webkit/tools/layout_tests/test_lists/win/tests_fixable.txt b/webkit/tools/layout_tests/test_lists/win/tests_fixable.txt
index b3cb9b4..8bf329c 100644
--- a/webkit/tools/layout_tests/test_lists/win/tests_fixable.txt
+++ b/webkit/tools/layout_tests/test_lists/win/tests_fixable.txt
@@ -669,10 +669,6 @@ V8 # LayoutTests/fast/js/date-set-to-nan.html = FAIL
# http://crbug.com/2844
V8 # SKIP : LayoutTests/http/tests/appcache = TIMEOUT | FAIL
-# GC issue with MessageChannels.
-# http://code.google.com/p/chromium/issues/detail?id=4195
-V8 # LayoutTests/fast/events/message-channel-gc.html = PASS | FAIL
-
# Depends on postMessage in a way we don't support:
# http://code.google.com/p/chromium/issues/detail?id=2857
V8 # LayoutTests/http/tests/security/dataURL/xss-DENIED-to-data-url-sub-frame-uppercase.html = FAIL