Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp

Issue 1688573002: ServiceWorkerMessageEvent shouldn't hold ScriptValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerMessageEvent.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
diff --git a/third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp b/third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
index 7ca9fcd39cf0613df783ff1b26ab008044b0a9f1..6caffeb536c1e5e59b09fdea5838c980f39ada4d 100644
--- a/third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
+++ b/third_party/WebKit/Source/bindings/modules/v8/custom/V8ServiceWorkerMessageEventCustom.cpp
@@ -5,10 +5,52 @@
#include "bindings/modules/v8/V8ServiceWorkerMessageEvent.h"
#include "bindings/core/v8/SerializedScriptValue.h"
+#include "bindings/core/v8/SerializedScriptValueFactory.h"
#include "bindings/core/v8/V8HiddenValue.h"
+#include "bindings/modules/v8/V8ServiceWorkerMessageEventInit.h"
namespace blink {
+void V8ServiceWorkerMessageEvent::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ ExceptionState exceptionState(ExceptionState::ConstructionContext, "ServiceWorkerMessageEvent", info.Holder(), info.GetIsolate());
+ if (UNLIKELY(info.Length() < 1)) {
+ setMinimumArityTypeError(exceptionState, 1, info.Length());
+ exceptionState.throwIfNeeded();
+ return;
+ }
+
+ V8StringResource<> type = info[0];
+ if (!type.prepare())
+ return;
+
+ ServiceWorkerMessageEventInit eventInitDict;
+ if (!isUndefinedOrNull(info[1])) {
+ if (!info[1]->IsObject()) {
+ exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not an object.");
+ exceptionState.throwIfNeeded();
+ return;
+ }
+ V8ServiceWorkerMessageEventInit::toImpl(info.GetIsolate(), info[1], eventInitDict, exceptionState);
+ if (exceptionState.throwIfNeeded())
+ return;
+ }
+
+ RefPtrWillBeRawPtr<ServiceWorkerMessageEvent> impl = ServiceWorkerMessageEvent::create(type, eventInitDict);
+ v8::Local<v8::Object> wrapper = info.Holder();
+ wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8ServiceWorkerMessageEvent::wrapperTypeInfo, wrapper);
+
+ // TODO(bashi): Workaround for http://crbug.com/529941. We need to store
+ // |data| as a hidden value to avoid cycle references.
+ if (eventInitDict.hasData()) {
+ v8::Local<v8::Value> v8Data = eventInitDict.data().v8Value();
+ V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), wrapper, V8HiddenValue::data(info.GetIsolate()), v8Data);
+ if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
+ impl->setSerializedData(SerializedScriptValueFactory::instance().createAndSwallowExceptions(info.GetIsolate(), v8Data));
+ }
+ v8SetReturnValue(info, wrapper);
+}
+
void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ServiceWorkerMessageEvent* event = V8ServiceWorkerMessageEvent::toImpl(info.Holder());
@@ -25,8 +67,14 @@ void V8ServiceWorkerMessageEvent::dataAttributeGetterCustom(const v8::FunctionCa
if (SerializedScriptValue* serializedValue = event->serializedData()) {
MessagePortArray ports = event->ports();
data = serializedValue->deserialize(isolate, &ports);
- } else {
- data = event->data().v8ValueFor(scriptState);
+ } else if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) {
+ v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenValueFromMainWorldWrapper(scriptState, event, V8HiddenValue::data(isolate));
+ if (!mainWorldData.IsEmpty()) {
+ // TODO(bashi): Enter the main world's ScriptState::Scope while
+ // serializing the main world's value.
+ event->setSerializedData(SerializedScriptValueFactory::instance().createAndSwallowExceptions(info.GetIsolate(), mainWorldData));
+ data = event->serializedData()->deserialize();
+ }
}
if (data.IsEmpty())
data = v8::Null(isolate);
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerMessageEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698