OLD | NEW |
---|---|
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 Loading... | |
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 } | |
haraken
2015/09/25 10:08:10
Just to confirm: The line 82 - 92 is the only diff
bashi
2015/09/28 05:22:57
Yes.
| |
93 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8CustomEvent::wrap perTypeInfo, wrapper); | |
haraken
2015/09/25 10:08:10
Remove this. You already execute this at line 80.
bashi
2015/09/28 05:22:57
Done.
| |
94 v8SetReturnValue(info, wrapper); | |
95 } | |
52 | 96 |
53 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v 8::Value>& info) | 97 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v 8::Value>& info) |
54 { | 98 { |
55 CustomEvent* event = V8CustomEvent::toImpl(info.Holder()); | 99 CustomEvent* event = V8CustomEvent::toImpl(info.Holder()); |
56 | 100 |
57 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate( ), info.Holder(), V8HiddenValue::detail(info.GetIsolate())); | 101 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate( ), info.Holder(), V8HiddenValue::detail(info.GetIsolate())); |
58 | 102 |
59 if (!result.IsEmpty()) { | 103 if (!result.IsEmpty()) { |
60 v8SetReturnValue(info, result); | 104 v8SetReturnValue(info, result); |
61 return; | 105 return; |
62 } | 106 } |
63 | 107 |
64 // Be careful not to return a V8 value which is created in different world. | 108 // Be careful not to return a V8 value which is created in different world. |
65 v8::Local<v8::Value> detail; | 109 v8::Local<v8::Value> detail; |
66 if (SerializedScriptValue* serializedValue = event->serializedDetail()) | 110 if (SerializedScriptValue* serializedValue = event->serializedDetail()) { |
67 detail = serializedValue->deserialize(); | 111 detail = serializedValue->deserialize(); |
68 else | 112 } else if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) { |
69 detail = event->detail().v8ValueFor(ScriptState::current(info.GetIsolate ())); | 113 v8::Local<v8::Value> mainWorldDetail = V8HiddenValue::getHiddenValueFrom MainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::detail(info.GetIsolate ())); |
114 if (!mainWorldDetail.IsEmpty()) | |
115 detail = SerializedScriptValueFactory::instance().createAndSwallowEx ceptions(info.GetIsolate(), mainWorldDetail)->deserialize(); | |
haraken
2015/09/25 10:08:10
At this point, wouldn't it be better to cache the
bashi
2015/09/28 05:22:57
Right. I overlooked that there could be more than
| |
116 } | |
117 | |
70 // |detail| should be null when it is an empty handle because its default va lue is null. | 118 // |detail| should be null when it is an empty handle because its default va lue is null. |
71 if (detail.IsEmpty()) | 119 if (detail.IsEmpty()) |
72 detail = v8::Null(info.GetIsolate()); | 120 detail = v8::Null(info.GetIsolate()); |
73 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail)) ; | 121 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail)) ; |
74 } | 122 } |
75 | 123 |
76 } // namespace blink | 124 } // namespace blink |
OLD | NEW |