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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8CustomEventCustom.cpp

Issue 1372513002: Store |detail| as a hidden value of custom event wrappers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/V8CustomEvent.h" 32 #include "bindings/core/v8/V8CustomEvent.h"
33 33
34 #include "bindings/core/v8/Dictionary.h" 34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/SerializedScriptValue.h" 35 #include "bindings/core/v8/SerializedScriptValue.h"
36 #include "bindings/core/v8/SerializedScriptValueFactory.h" 36 #include "bindings/core/v8/SerializedScriptValueFactory.h"
37 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
38 #include "bindings/core/v8/V8CustomEventInit.h"
38 #include "bindings/core/v8/V8DOMWrapper.h" 39 #include "bindings/core/v8/V8DOMWrapper.h"
39 #include "bindings/core/v8/V8Event.h" 40 #include "bindings/core/v8/V8Event.h"
40 #include "bindings/core/v8/V8HiddenValue.h" 41 #include "bindings/core/v8/V8HiddenValue.h"
41 #include "core/dom/ContextFeatures.h" 42 #include "core/dom/ContextFeatures.h"
42 #include "platform/RuntimeEnabledFeatures.h" 43 #include "platform/RuntimeEnabledFeatures.h"
43 44
44 namespace blink { 45 namespace blink {
45 46
46 static v8::Local<v8::Value> cacheState(v8::Isolate* isolate, v8::Local<v8::Objec t> customEvent, v8::Local<v8::Value> detail) 47 static v8::Local<v8::Value> cacheState(v8::Isolate* isolate, v8::Local<v8::Objec t> customEvent, v8::Local<v8::Value> detail)
47 { 48 {
48 V8HiddenValue::setHiddenValue(isolate, customEvent, V8HiddenValue::detail(is olate), detail); 49 V8HiddenValue::setHiddenValue(isolate, customEvent, V8HiddenValue::detail(is olate), detail);
49 return detail; 50 return detail;
50 } 51 }
51 52
53 void V8CustomEvent::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
54 {
55 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEv ent", info.Holder(), info.GetIsolate());
56 if (UNLIKELY(info.Length() < 1)) {
57 setMinimumArityTypeError(exceptionState, 1, info.Length());
58 exceptionState.throwIfNeeded();
59 return;
60 }
61
62 V8StringResource<> type = info[0];
63 if (!type.prepare())
64 return;
65
66 CustomEventInit eventInitDict;
67 if (!isUndefinedOrNull(info[1])) {
68 if (!info[1]->IsObject()) {
69 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not an object.");
70 exceptionState.throwIfNeeded();
71 return;
72 }
73 V8CustomEventInit::toImpl(info.GetIsolate(), info[1], eventInitDict, exc eptionState);
74 if (exceptionState.throwIfNeeded())
75 return;
76 }
77
78 RefPtrWillBeRawPtr<CustomEvent> impl = CustomEvent::create(type, eventInitDi ct);
79 v8::Local<v8::Object> wrapper = info.Holder();
80 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8CustomEvent::wrap perTypeInfo, wrapper);
81
82 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store
83 // |detail| as a hidden value to avoid cycle references.
84 if (eventInitDict.hasDetail()) {
85 v8::Local<v8::Value> v8Detail = eventInitDict.detail().v8Value();
86 cacheState(info.GetIsolate(), wrapper, v8Detail);
87 // When a custom event is created in an isolated world, serialize
88 // |detail| and store it in |impl| so that we can clone |detail|
89 // when the getter of |detail| is called in the main world later.
90 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
91 impl->setSerializedDetail(SerializedScriptValueFactory::instance().c reateAndSwallowExceptions(info.GetIsolate(), v8Detail));
92 }
93 v8SetReturnValue(info, wrapper);
94 }
52 95
53 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v 8::Value>& info) 96 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v 8::Value>& info)
54 { 97 {
55 CustomEvent* event = V8CustomEvent::toImpl(info.Holder()); 98 CustomEvent* event = V8CustomEvent::toImpl(info.Holder());
56 99
57 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate( ), info.Holder(), V8HiddenValue::detail(info.GetIsolate())); 100 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate( ), info.Holder(), V8HiddenValue::detail(info.GetIsolate()));
58 101
59 if (!result.IsEmpty()) { 102 if (!result.IsEmpty()) {
60 v8SetReturnValue(info, result); 103 v8SetReturnValue(info, result);
61 return; 104 return;
62 } 105 }
63 106
64 // Be careful not to return a V8 value which is created in different world. 107 // Be careful not to return a V8 value which is created in different world.
65 v8::Local<v8::Value> detail; 108 v8::Local<v8::Value> detail;
66 if (SerializedScriptValue* serializedValue = event->serializedDetail()) 109 if (SerializedScriptValue* serializedValue = event->serializedDetail()) {
67 detail = serializedValue->deserialize(); 110 detail = serializedValue->deserialize();
68 else 111 } else if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) {
69 detail = event->detail().v8ValueFor(ScriptState::current(info.GetIsolate ())); 112 v8::Local<v8::Value> mainWorldDetail = V8HiddenValue::getHiddenValueFrom MainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::detail(info.GetIsolate ()));
113 if (!mainWorldDetail.IsEmpty()) {
114 event->setSerializedDetail(SerializedScriptValueFactory::instance(). createAndSwallowExceptions(info.GetIsolate(), mainWorldDetail));
115 detail = event->serializedDetail()->deserialize();
116 }
117 }
118
70 // |detail| should be null when it is an empty handle because its default va lue is null. 119 // |detail| should be null when it is an empty handle because its default va lue is null.
71 if (detail.IsEmpty()) 120 if (detail.IsEmpty())
72 detail = v8::Null(info.GetIsolate()); 121 detail = v8::Null(info.GetIsolate());
73 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail)) ; 122 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail)) ;
74 } 123 }
75 124
76 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698