diff options
author | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 13:14:36 +0000 |
---|---|---|
committer | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 13:14:36 +0000 |
commit | e381cb6c17928feb309e27867eba03c5cd8b7483 (patch) | |
tree | bd8abaac357d9ca4049111c64b3181703a725810 | |
parent | 400d807b0c567a1df1087694627737174a13c8ad (diff) | |
download | chromium_src-e381cb6c17928feb309e27867eba03c5cd8b7483.zip chromium_src-e381cb6c17928feb309e27867eba03c5cd8b7483.tar.gz chromium_src-e381cb6c17928feb309e27867eba03c5cd8b7483.tar.bz2 |
Unfork MessagePort.cpp by postponing the entanglement of the message port JavaScript wrappers to GC time.
This have the drawback that message ports are "re-entangled/re-unentangled" for each GC which happens. This will most likely not make any noticable difference.
Review URL: http://codereview.chromium.org/14150
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7053 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.cpp | 31 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptController.h | 4 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 37 |
3 files changed, 37 insertions, 35 deletions
diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp index 1e4ffe4..99e35aa3 100644 --- a/webkit/port/bindings/v8/ScriptController.cpp +++ b/webkit/port/bindings/v8/ScriptController.cpp @@ -107,37 +107,6 @@ void ScriptController::gcUnprotectJSWrapper(void* dom_object) V8Proxy::GCUnprotect(dom_object); } -void ScriptController::entangleMessagePorts(MessagePort *port1, - MessagePort *port2) -{ - // When two message ports are entangled make sure that the two wrappers are - // also entangled. If one of the ports has pending activity it's wrapper - // will be protected from beeing GC'ed and by entangeling the wrappers the - // wrapper for the entangled port will also be protected. - v8::Handle<v8::Value> port1_wrapper = - V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port1); - v8::Handle<v8::Value> port2_wrapper = - V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port2); - ASSERT(port1_wrapper->IsObject()); - v8::Handle<v8::Object>::Cast(port1_wrapper)->SetInternalField( - V8Custom::kMessagePortEntangledPortIndex, port2_wrapper); - ASSERT(port2_wrapper->IsObject()); - v8::Handle<v8::Object>::Cast(port2_wrapper)->SetInternalField( - V8Custom::kMessagePortEntangledPortIndex, port1_wrapper); -} - -void ScriptController::unentangleMessagePort(MessagePort *port) -{ - // Remove the wrapper entanglement when a port is unentangled. - if (V8Proxy::DOMObjectHasJSWrapper(port)) { - v8::Handle<v8::Value> wrapper = - V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port); - ASSERT(wrapper->IsObject()); - v8::Handle<v8::Object>::Cast(wrapper)->SetInternalField( - V8Custom::kMessagePortEntangledPortIndex, v8::Undefined()); - } -} - ScriptController::ScriptController(Frame* frame) : m_frame(frame) , m_sourceURL(0) diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h index e42ecfb..16f2de8 100644 --- a/webkit/port/bindings/v8/ScriptController.h +++ b/webkit/port/bindings/v8/ScriptController.h @@ -206,10 +206,6 @@ public: static void gcProtectJSWrapper(void* object); static void gcUnprotectJSWrapper(void* object); - // Handle entangle/unentangle of message ports. - static void entangleMessagePorts(MessagePort *port1, MessagePort *port2); - static void unentangleMessagePort(MessagePort *port); - // Get/Set RecordPlaybackMode flag. // This is a special mode where JS helps the browser implement // playback/record mode. Generally, in this mode, some functions diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index 3bf5b5b..06e9aaf 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -674,6 +674,43 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) ASSERT(false); #undef MAKE_CASE } + + // Additional handling of message port ensuring that entangled ports also + // have their wrappers entangled. This should ideally be handled when the + // ports are actually entangled in MessagePort::entangle, but to avoid + // forking MessagePort.* this is postponed to GC time. Having this postponed + // has the drawback that the wrappers are "entangled/unentangled" for each + // GC even though their entnaglement most likely is still the same. + if (type == V8ClassIndex::MESSAGEPORT) { + // Get the port and its entangled port. + MessagePort* port1 = static_cast<MessagePort*>(obj); + MessagePort* port2 = port1->entangledPort(); + if (port2 != NULL) { + // As ports are always entangled in pairs only perform the entanglement + // once for each pair (see ASSERT in MessagePort::unentangle()). + if (port1 < port2) { + v8::Handle<v8::Value> port1_wrapper = + V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port1); + v8::Handle<v8::Value> port2_wrapper = + V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port2); + ASSERT(port1_wrapper->IsObject()); + v8::Handle<v8::Object>::Cast(port1_wrapper)->SetInternalField( + V8Custom::kMessagePortEntangledPortIndex, port2_wrapper); + ASSERT(port2_wrapper->IsObject()); + v8::Handle<v8::Object>::Cast(port2_wrapper)->SetInternalField( + V8Custom::kMessagePortEntangledPortIndex, port1_wrapper); + } + } else { + // Remove the wrapper entanglement when a port is not entangled. + if (V8Proxy::DOMObjectHasJSWrapper(port1)) { + v8::Handle<v8::Value> wrapper = + V8Proxy::ToV8Object(V8ClassIndex::MESSAGEPORT, port1); + ASSERT(wrapper->IsObject()); + v8::Handle<v8::Object>::Cast(wrapper)->SetInternalField( + V8Custom::kMessagePortEntangledPortIndex, v8::Undefined()); + } + } + } } // Create object groups. |