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

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

Issue 2007463003: binding: Reimplements V8HiddenValue as V8PrivateProperty. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 4 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
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 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 "bindings/core/v8/V8MessageEvent.h" 31 #include "bindings/core/v8/V8MessageEvent.h"
32 32
33 #include "bindings/core/v8/SerializedScriptValue.h" 33 #include "bindings/core/v8/SerializedScriptValue.h"
34 #include "bindings/core/v8/SerializedScriptValueFactory.h" 34 #include "bindings/core/v8/SerializedScriptValueFactory.h"
35 #include "bindings/core/v8/V8ArrayBuffer.h" 35 #include "bindings/core/v8/V8ArrayBuffer.h"
36 #include "bindings/core/v8/V8Binding.h" 36 #include "bindings/core/v8/V8Binding.h"
37 #include "bindings/core/v8/V8Blob.h" 37 #include "bindings/core/v8/V8Blob.h"
38 #include "bindings/core/v8/V8HiddenValue.h"
39 #include "bindings/core/v8/V8MessagePort.h" 38 #include "bindings/core/v8/V8MessagePort.h"
39 #include "bindings/core/v8/V8PrivateProperty.h"
40 #include "bindings/core/v8/V8Window.h" 40 #include "bindings/core/v8/V8Window.h"
41 #include "core/events/MessageEvent.h"
42 41
43 namespace blink { 42 namespace blink {
44 43
45 void V8MessageEvent::dataAttributeGetterCustom(const v8::FunctionCallbackInfo<v8 ::Value>& info) 44 void V8MessageEvent::dataAttributeGetterCustom(const v8::FunctionCallbackInfo<v8 ::Value>& info)
46 { 45 {
47 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); 46 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
48 v8::Local<v8::Value> cachedData = V8HiddenValue::getHiddenValue(scriptState, info.Holder(), V8HiddenValue::data(info.GetIsolate())); 47 auto privateCachedData = V8PrivateProperty::getMessageEventCachedData(info.G etIsolate());
48 v8::Local<v8::Value> cachedData = privateCachedData.get(scriptState->context (), info.Holder());
49 if (!cachedData.IsEmpty()) { 49 if (!cachedData.IsEmpty()) {
50 v8SetReturnValue(info, cachedData); 50 v8SetReturnValue(info, cachedData);
51 return; 51 return;
52 } 52 }
53 53
54 MessageEvent* event = V8MessageEvent::toImpl(info.Holder()); 54 MessageEvent* event = V8MessageEvent::toImpl(info.Holder());
55 55
56 v8::Local<v8::Value> result; 56 v8::Local<v8::Value> result;
57 switch (event->getDataType()) { 57 switch (event->getDataType()) {
58 case MessageEvent::DataTypeScriptValue: 58 case MessageEvent::DataTypeScriptValue:
59 result = event->dataAsScriptValue().v8ValueFor(scriptState); 59 result = event->dataAsScriptValue().v8ValueFor(scriptState);
60 if (result.IsEmpty()) 60 if (result.IsEmpty())
61 result = v8::Null(info.GetIsolate()); 61 result = v8::Null(info.GetIsolate());
62 break; 62 break;
63 63
64 case MessageEvent::DataTypeSerializedScriptValue: 64 case MessageEvent::DataTypeSerializedScriptValue:
65 if (SerializedScriptValue* serializedValue = event->dataAsSerializedScri ptValue()) { 65 if (SerializedScriptValue* serializedValue = event->dataAsSerializedScri ptValue()) {
66 MessagePortArray ports = event->ports(); 66 MessagePortArray ports = event->ports();
67 result = serializedValue->deserialize(info.GetIsolate(), &ports); 67 result = serializedValue->deserialize(info.GetIsolate(), &ports);
68 } else { 68 } else {
69 result = v8::Null(info.GetIsolate()); 69 result = v8::Null(info.GetIsolate());
70 } 70 }
71 break; 71 break;
72 72
73 case MessageEvent::DataTypeString: { 73 case MessageEvent::DataTypeString:
74 result = V8HiddenValue::getHiddenValue(scriptState, info.Holder(), V8Hid denValue::stringData(info.GetIsolate())); 74 result = v8String(info.GetIsolate(), event->dataAsString());
75 if (result.IsEmpty()) {
76 String stringValue = event->dataAsString();
77 result = v8String(info.GetIsolate(), stringValue);
78 }
79 break; 75 break;
80 }
81 76
82 case MessageEvent::DataTypeBlob: 77 case MessageEvent::DataTypeBlob:
83 result = toV8(event->dataAsBlob(), info.Holder(), info.GetIsolate()); 78 result = toV8(event->dataAsBlob(), info.Holder(), info.GetIsolate());
84 break; 79 break;
85 80
86 case MessageEvent::DataTypeArrayBuffer: 81 case MessageEvent::DataTypeArrayBuffer:
87 result = V8HiddenValue::getHiddenValue(scriptState, info.Holder(), V8Hid denValue::arrayBufferData(info.GetIsolate())); 82 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIsolate ());
88 if (result.IsEmpty())
89 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late());
90 break; 83 break;
91 } 84 }
92 85
93 // Store the result as a hidden value so this callback returns the cached 86 // Store the result as a private value so this callback returns the cached
94 // result in future invocations. 87 // result in future invocations.
95 V8HiddenValue::setHiddenValue(scriptState, info.Holder(), V8HiddenValue::da ta(info.GetIsolate()), result); 88 privateCachedData.set(scriptState->context(), info.Holder(), result);
96 v8SetReturnValue(info, result); 89 v8SetReturnValue(info, result);
97 } 90 }
98 91
99 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info) 92 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info)
100 { 93 {
101 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initMessage Event", "MessageEvent", info.Holder(), info.GetIsolate()); 94 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initMessage Event", "MessageEvent", info.Holder(), info.GetIsolate());
102 MessageEvent* event = V8MessageEvent::toImpl(info.Holder()); 95 MessageEvent* event = V8MessageEvent::toImpl(info.Holder());
103 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]); 96 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
104 bool canBubbleArg = false; 97 bool canBubbleArg = false;
105 bool cancelableArg = false; 98 bool cancelableArg = false;
106 if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), c anBubbleArg) 99 if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), c anBubbleArg)
107 || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()) , cancelableArg)) 100 || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()) , cancelableArg))
108 return; 101 return;
109 v8::Local<v8::Value> dataArg = info[3]; 102 v8::Local<v8::Value> dataArg = info[3];
110 TOSTRING_VOID(V8StringResource<>, originArg, info[4]); 103 TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
111 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]); 104 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
112 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]); 105 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]);
113 MessagePortArray* portArray = nullptr; 106 MessagePortArray* portArray = nullptr;
114 const int portArrayIndex = 7; 107 const int portArrayIndex = 7;
115 if (!isUndefinedOrNull(info[portArrayIndex])) { 108 if (!isUndefinedOrNull(info[portArrayIndex])) {
116 portArray = new MessagePortArray; 109 portArray = new MessagePortArray;
117 *portArray = toMemberNativeArray<MessagePort>(info[portArrayIndex], port ArrayIndex + 1, info.GetIsolate(), exceptionState); 110 *portArray = toMemberNativeArray<MessagePort>(info[portArrayIndex], port ArrayIndex + 1, info.GetIsolate(), exceptionState);
118 if (exceptionState.throwIfNeeded()) 111 if (exceptionState.throwIfNeeded())
119 return; 112 return;
120 } 113 }
121 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, ScriptValue(Sc riptState::current(info.GetIsolate()), dataArg), originArg, lastEventIdArg, sour ceArg, portArray); 114 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, ScriptValue(Sc riptState::current(info.GetIsolate()), dataArg), originArg, lastEventIdArg, sour ceArg, portArray);
122 } 115 }
123 116
124 } // namespace blink 117 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8PrivateProperty.cpp ('k') | third_party/WebKit/Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698