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

Side by Side Diff: Source/bindings/core/v8/custom/V8MessageEventCustom.cpp

Issue 1150183007: Re-land: bindings: Use MessageEventInit for MessageEvent constructor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/events/MessageEvent.h" 42 #include "core/events/MessageEvent.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 void V8MessageEvent::dataAttributeGetterCustom(const v8::PropertyCallbackInfo<v8 ::Value>& info) 46 void V8MessageEvent::dataAttributeGetterCustom(const v8::PropertyCallbackInfo<v8 ::Value>& info)
47 { 47 {
48 MessageEvent* event = V8MessageEvent::toImpl(info.Holder()); 48 MessageEvent* event = V8MessageEvent::toImpl(info.Holder());
49 49
50 v8::Local<v8::Value> result; 50 v8::Local<v8::Value> result;
51 switch (event->dataType()) { 51 switch (event->dataType()) {
52 case MessageEvent::DataTypeScriptValue: { 52 case MessageEvent::DataTypeScriptValue:
53 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate())); 53 result = event->dataAsScriptValue().v8ValueFor(ScriptState::current(info .GetIsolate()));
54 if (result.IsEmpty()) { 54 if (result.IsEmpty())
55 if (!event->dataAsSerializedScriptValue()) { 55 result = v8::Null(info.GetIsolate());
56 // If we're in an isolated world and the event was created in th e main world,
57 // we need to find the 'data' property on the main world wrapper and clone it.
58 v8::Local<v8::Value> mainWorldData = V8HiddenValue::getHiddenVal ueFromMainWorldWrapper(info.GetIsolate(), event, V8HiddenValue::data(info.GetIso late()));
59 if (!mainWorldData.IsEmpty())
60 event->setSerializedData(SerializedScriptValueFactory::insta nce().createAndSwallowExceptions(info.GetIsolate(), mainWorldData));
61 }
62 if (event->dataAsSerializedScriptValue())
63 result = event->dataAsSerializedScriptValue()->deserialize(info. GetIsolate());
64 else
65 result = v8::Null(info.GetIsolate());
66 }
67 break; 56 break;
68 }
69 57
70 case MessageEvent::DataTypeSerializedScriptValue: 58 case MessageEvent::DataTypeSerializedScriptValue:
71 if (SerializedScriptValue* serializedValue = event->dataAsSerializedScri ptValue()) { 59 if (SerializedScriptValue* serializedValue = event->dataAsSerializedScri ptValue()) {
72 MessagePortArray ports = event->ports(); 60 MessagePortArray ports = event->ports();
73 result = serializedValue->deserialize(info.GetIsolate(), &ports); 61 result = serializedValue->deserialize(info.GetIsolate(), &ports);
74 } else { 62 } else {
75 result = v8::Null(info.GetIsolate()); 63 result = v8::Null(info.GetIsolate());
76 } 64 }
77 break; 65 break;
78 66
(...skipping 12 matching lines...) Expand all
91 79
92 case MessageEvent::DataTypeArrayBuffer: 80 case MessageEvent::DataTypeArrayBuffer:
93 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate())); 81 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate()));
94 if (result.IsEmpty()) 82 if (result.IsEmpty())
95 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late()); 83 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late());
96 break; 84 break;
97 } 85 }
98 86
99 // Overwrite the data attribute so it returns the cached result in future in vocations. 87 // Overwrite the data attribute so it returns the cached result in future in vocations.
100 // This custom getter handler will not be called again. 88 // This custom getter handler will not be called again.
89 // TODO(bashi): We use ForceSet() here, and we use hidden values in other
90 // places (e.g. V8CustomEventCustom.cpp). We should use the same way to
91 // handle "any" attributes.
101 v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::Dont Delete | v8::ReadOnly); 92 v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::Dont Delete | v8::ReadOnly);
102 if (!v8CallBoolean(info.Holder()->ForceSet(info.GetIsolate()->GetCurrentCont ext(), v8AtomicString(info.GetIsolate(), "data"), result, dataAttr))) { 93 if (!v8CallBoolean(info.Holder()->ForceSet(info.GetIsolate()->GetCurrentCont ext(), v8AtomicString(info.GetIsolate(), "data"), result, dataAttr))) {
103 v8SetReturnValue(info, v8::Null(info.GetIsolate())); 94 v8SetReturnValue(info, v8::Null(info.GetIsolate()));
104 return; 95 return;
105 } 96 }
106 v8SetReturnValue(info, result); 97 v8SetReturnValue(info, result);
107 } 98 }
108 99
109 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info) 100 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info)
110 { 101 {
(...skipping 10 matching lines...) Expand all
121 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]); 112 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
122 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]); 113 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]);
123 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr; 114 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
124 const int portArrayIndex = 7; 115 const int portArrayIndex = 7;
125 if (!isUndefinedOrNull(info[portArrayIndex])) { 116 if (!isUndefinedOrNull(info[portArrayIndex])) {
126 portArray = adoptPtrWillBeNoop(new MessagePortArray); 117 portArray = adoptPtrWillBeNoop(new MessagePortArray);
127 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState); 118 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState);
128 if (exceptionState.throwIfNeeded()) 119 if (exceptionState.throwIfNeeded())
129 return; 120 return;
130 } 121 }
131 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, originArg, las tEventIdArg, sourceArg, portArray.release()); 122 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, ScriptValue(Sc riptState::current(info.GetIsolate()), dataArg), originArg, lastEventIdArg, sour ceArg, portArray.release());
132
133 if (!dataArg.IsEmpty()) {
134 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8Hidden Value::data(info.GetIsolate()), dataArg);
135 if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
136 event->setSerializedData(SerializedScriptValueFactory::instance().cr eateAndSwallowExceptions(info.GetIsolate(), dataArg));
137 }
138 } 123 }
139 124
140 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698