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

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

Issue 1184603002: bindings: Use hidden value instead of ForceSet() in V8MessageEventCustom (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 27 matching lines...) Expand all
38 #include "bindings/core/v8/V8Blob.h" 38 #include "bindings/core/v8/V8Blob.h"
39 #include "bindings/core/v8/V8HiddenValue.h" 39 #include "bindings/core/v8/V8HiddenValue.h"
40 #include "bindings/core/v8/V8MessagePort.h" 40 #include "bindings/core/v8/V8MessagePort.h"
41 #include "bindings/core/v8/V8Window.h" 41 #include "bindings/core/v8/V8Window.h"
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 v8::Local<v8::Value> cachedData = V8HiddenValue::getHiddenValue(info.GetIsol ate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()));
49 if (!cachedData.IsEmpty()) {
50 v8SetReturnValue(info, cachedData);
51 return;
52 }
53
48 MessageEvent* event = V8MessageEvent::toImpl(info.Holder()); 54 MessageEvent* event = V8MessageEvent::toImpl(info.Holder());
49 55
50 v8::Local<v8::Value> result; 56 v8::Local<v8::Value> result;
51 switch (event->dataType()) { 57 switch (event->dataType()) {
52 case MessageEvent::DataTypeScriptValue: 58 case MessageEvent::DataTypeScriptValue:
53 result = event->dataAsScriptValue().v8ValueFor(ScriptState::current(info .GetIsolate())); 59 result = event->dataAsScriptValue().v8ValueFor(ScriptState::current(info .GetIsolate()));
54 if (result.IsEmpty()) 60 if (result.IsEmpty())
55 result = v8::Null(info.GetIsolate()); 61 result = v8::Null(info.GetIsolate());
56 break; 62 break;
57 63
(...skipping 19 matching lines...) Expand all
77 result = toV8(event->dataAsBlob(), info.Holder(), info.GetIsolate()); 83 result = toV8(event->dataAsBlob(), info.Holder(), info.GetIsolate());
78 break; 84 break;
79 85
80 case MessageEvent::DataTypeArrayBuffer: 86 case MessageEvent::DataTypeArrayBuffer:
81 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate())); 87 result = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::arrayBufferData(info.GetIsolate()));
82 if (result.IsEmpty()) 88 if (result.IsEmpty())
83 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late()); 89 result = toV8(event->dataAsArrayBuffer(), info.Holder(), info.GetIso late());
84 break; 90 break;
85 } 91 }
86 92
87 // Overwrite the data attribute so it returns the cached result in future in vocations. 93 // Store the result as a hidden value so this callback returns the cached
88 // This custom getter handler will not be called again. 94 // result in future invocations.
89 // TODO(bashi): We use ForceSet() here, and we use hidden values in other 95 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenVal ue::data(info.GetIsolate()), result);
90 // places (e.g. V8CustomEventCustom.cpp). We should use the same way to
91 // handle "any" attributes.
92 v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::Dont Delete | v8::ReadOnly);
93 if (!v8CallBoolean(info.Holder()->ForceSet(info.GetIsolate()->GetCurrentCont ext(), v8AtomicString(info.GetIsolate(), "data"), result, dataAttr))) {
94 v8SetReturnValue(info, v8::Null(info.GetIsolate()));
95 return;
96 }
97 v8SetReturnValue(info, result); 96 v8SetReturnValue(info, result);
98 } 97 }
99 98
100 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info) 99 void V8MessageEvent::initMessageEventMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& info)
101 { 100 {
102 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initMessage Event", "MessageEvent", info.Holder(), info.GetIsolate()); 101 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initMessage Event", "MessageEvent", info.Holder(), info.GetIsolate());
103 MessageEvent* event = V8MessageEvent::toImpl(info.Holder()); 102 MessageEvent* event = V8MessageEvent::toImpl(info.Holder());
104 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]); 103 TOSTRING_VOID(V8StringResource<>, typeArg, info[0]);
105 bool canBubbleArg; 104 bool canBubbleArg;
106 bool cancelableArg; 105 bool cancelableArg;
107 if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), c anBubbleArg) 106 if (!v8Call(info[1]->BooleanValue(info.GetIsolate()->GetCurrentContext()), c anBubbleArg)
108 || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()) , cancelableArg)) 107 || !v8Call(info[2]->BooleanValue(info.GetIsolate()->GetCurrentContext()) , cancelableArg))
109 return; 108 return;
110 v8::Local<v8::Value> dataArg = info[3]; 109 v8::Local<v8::Value> dataArg = info[3];
111 TOSTRING_VOID(V8StringResource<>, originArg, info[4]); 110 TOSTRING_VOID(V8StringResource<>, originArg, info[4]);
112 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]); 111 TOSTRING_VOID(V8StringResource<>, lastEventIdArg, info[5]);
113 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]); 112 DOMWindow* sourceArg = toDOMWindow(info.GetIsolate(), info[6]);
114 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr; 113 OwnPtrWillBeRawPtr<MessagePortArray> portArray = nullptr;
115 const int portArrayIndex = 7; 114 const int portArrayIndex = 7;
116 if (!isUndefinedOrNull(info[portArrayIndex])) { 115 if (!isUndefinedOrNull(info[portArrayIndex])) {
117 portArray = adoptPtrWillBeNoop(new MessagePortArray); 116 portArray = adoptPtrWillBeNoop(new MessagePortArray);
118 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState); 117 *portArray = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort> (info[portArrayIndex], portArrayIndex + 1, info.GetIsolate(), exceptionState);
119 if (exceptionState.throwIfNeeded()) 118 if (exceptionState.throwIfNeeded())
120 return; 119 return;
121 } 120 }
122 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, ScriptValue(Sc riptState::current(info.GetIsolate()), dataArg), originArg, lastEventIdArg, sour ceArg, portArray.release()); 121 event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, ScriptValue(Sc riptState::current(info.GetIsolate()), dataArg), originArg, lastEventIdArg, sour ceArg, portArray.release());
123 } 122 }
124 123
125 } // namespace blink 124 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698