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 static void storeDetail(v8::Isolate* isolate, CustomEvent* impl, v8::Local<v8::O
bject> wrapper, v8::Local<v8::Value> detail) |
| 54 { |
| 55 cacheState(isolate, wrapper, detail); |
| 56 // When a custom event is created in an isolated world, serialize |
| 57 // |detail| and store it in |impl| so that we can clone |detail| |
| 58 // when the getter of |detail| is called in the main world later. |
| 59 if (DOMWrapperWorld::current(isolate).isIsolatedWorld()) |
| 60 impl->setSerializedDetail(SerializedScriptValueFactory::instance().creat
eAndSwallowExceptions(isolate, detail)); |
| 61 } |
| 62 |
| 63 void V8CustomEvent::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) |
| 64 { |
| 65 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEv
ent", info.Holder(), info.GetIsolate()); |
| 66 if (UNLIKELY(info.Length() < 1)) { |
| 67 setMinimumArityTypeError(exceptionState, 1, info.Length()); |
| 68 exceptionState.throwIfNeeded(); |
| 69 return; |
| 70 } |
| 71 |
| 72 V8StringResource<> type = info[0]; |
| 73 if (!type.prepare()) |
| 74 return; |
| 75 |
| 76 CustomEventInit eventInitDict; |
| 77 if (!isUndefinedOrNull(info[1])) { |
| 78 if (!info[1]->IsObject()) { |
| 79 exceptionState.throwTypeError("parameter 2 ('eventInitDict') is not
an object."); |
| 80 exceptionState.throwIfNeeded(); |
| 81 return; |
| 82 } |
| 83 V8CustomEventInit::toImpl(info.GetIsolate(), info[1], eventInitDict, exc
eptionState); |
| 84 if (exceptionState.throwIfNeeded()) |
| 85 return; |
| 86 } |
| 87 |
| 88 RefPtrWillBeRawPtr<CustomEvent> impl = CustomEvent::create(type, eventInitDi
ct); |
| 89 v8::Local<v8::Object> wrapper = info.Holder(); |
| 90 wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8CustomEvent::wrap
perTypeInfo, wrapper); |
| 91 |
| 92 // TODO(bashi): Workaround for http://crbug.com/529941. We need to store |
| 93 // |detail| as a hidden value to avoid cycle references. |
| 94 if (eventInitDict.hasDetail()) { |
| 95 v8::Local<v8::Value> v8Detail = eventInitDict.detail().v8Value(); |
| 96 storeDetail(info.GetIsolate(), impl.get(), wrapper, v8Detail); |
| 97 } |
| 98 v8SetReturnValue(info, wrapper); |
| 99 } |
| 100 |
| 101 void V8CustomEvent::initCustomEventMethodEpilogueCustom(const v8::FunctionCallba
ckInfo<v8::Value>& info, CustomEvent* impl) |
| 102 { |
| 103 ASSERT(info.Length() >= 3); |
| 104 v8::Local<v8::Value> detail = info[3]; |
| 105 if (!detail.IsEmpty()) |
| 106 storeDetail(info.GetIsolate(), impl, info.Holder(), detail); |
| 107 } |
52 | 108 |
53 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v
8::Value>& info) | 109 void V8CustomEvent::detailAttributeGetterCustom(const v8::FunctionCallbackInfo<v
8::Value>& info) |
54 { | 110 { |
55 CustomEvent* event = V8CustomEvent::toImpl(info.Holder()); | 111 CustomEvent* event = V8CustomEvent::toImpl(info.Holder()); |
56 | 112 |
57 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate(
), info.Holder(), V8HiddenValue::detail(info.GetIsolate())); | 113 v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(info.GetIsolate(
), info.Holder(), V8HiddenValue::detail(info.GetIsolate())); |
58 | 114 |
59 if (!result.IsEmpty()) { | 115 if (!result.IsEmpty()) { |
60 v8SetReturnValue(info, result); | 116 v8SetReturnValue(info, result); |
61 return; | 117 return; |
62 } | 118 } |
63 | 119 |
64 // Be careful not to return a V8 value which is created in different world. | 120 // Be careful not to return a V8 value which is created in different world. |
65 v8::Local<v8::Value> detail; | 121 v8::Local<v8::Value> detail; |
66 if (SerializedScriptValue* serializedValue = event->serializedDetail()) | 122 if (SerializedScriptValue* serializedValue = event->serializedDetail()) { |
67 detail = serializedValue->deserialize(); | 123 detail = serializedValue->deserialize(); |
68 else | 124 } else if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld()) { |
69 detail = event->detail().v8ValueFor(ScriptState::current(info.GetIsolate
())); | 125 v8::Local<v8::Value> mainWorldDetail = V8HiddenValue::getHiddenValueFrom
MainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::detail(info.GetIsolate
())); |
| 126 if (!mainWorldDetail.IsEmpty()) { |
| 127 event->setSerializedDetail(SerializedScriptValueFactory::instance().
createAndSwallowExceptions(info.GetIsolate(), mainWorldDetail)); |
| 128 detail = event->serializedDetail()->deserialize(); |
| 129 } |
| 130 } |
| 131 |
70 // |detail| should be null when it is an empty handle because its default va
lue is null. | 132 // |detail| should be null when it is an empty handle because its default va
lue is null. |
71 if (detail.IsEmpty()) | 133 if (detail.IsEmpty()) |
72 detail = v8::Null(info.GetIsolate()); | 134 detail = v8::Null(info.GetIsolate()); |
73 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail))
; | 135 v8SetReturnValue(info, cacheState(info.GetIsolate(), info.Holder(), detail))
; |
74 } | 136 } |
75 | 137 |
76 } // namespace blink | 138 } // namespace blink |
OLD | NEW |