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

Side by Side Diff: Source/bindings/core/v8/PostMessage.h

Issue 1025203002: Have postMessage()s throw TypeError on failed arity checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: tidy up incorrect postMessage() usage Created 5 years, 9 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PostMessage_h 5 #ifndef PostMessage_h
6 #define PostMessage_h 6 #define PostMessage_h
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/SerializedScriptValue.h" 9 #include "bindings/core/v8/SerializedScriptValue.h"
10 #include "bindings/core/v8/SerializedScriptValueFactory.h" 10 #include "bindings/core/v8/SerializedScriptValueFactory.h"
11 #include "bindings/core/v8/V8Binding.h" 11 #include "bindings/core/v8/V8Binding.h"
12 #include "bindings/core/v8/V8BindingMacros.h" 12 #include "bindings/core/v8/V8BindingMacros.h"
13 #include "core/dom/DOMArrayBuffer.h" 13 #include "core/dom/DOMArrayBuffer.h"
14 #include "core/dom/MessagePort.h" 14 #include "core/dom/MessagePort.h"
15 #include <v8.h> 15 #include <v8.h>
16 16
17 namespace blink { 17 namespace blink {
18 18
19 class ExecutionContext; 19 class ExecutionContext;
20 20
21 // FIXME: This should be auto-generated by a code generator template. 21 // FIXME: This should be auto-generated by a code generator template.
22 template <class Type> 22 template <class Type>
23 void postMessageMethodCommon(const char* interfaceName, Type* instance, const v8 ::FunctionCallbackInfo<v8::Value>& info) 23 void postMessageMethodCommon(const char* interfaceName, Type* instance, const v8 ::FunctionCallbackInfo<v8::Value>& info)
24 { 24 {
25 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", interfaceName, info.Holder(), info.GetIsolate()); 25 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", interfaceName, info.Holder(), info.GetIsolate());
26 if (UNLIKELY(info.Length() < 1)) {
27 setMinimumArityTypeError(exceptionState, 1, info.Length());
28 exceptionState.throwIfNeeded();
29 return;
30 }
26 MessagePortArray ports; 31 MessagePortArray ports;
27 ArrayBufferArray arrayBuffers; 32 ArrayBufferArray arrayBuffers;
28 if (info.Length() > 1) { 33 if (info.Length() > 1) {
29 const int transferablesArgIndex = 1; 34 const int transferablesArgIndex = 1;
30 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionSt ate)) { 35 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionSt ate)) {
31 exceptionState.throwIfNeeded(); 36 exceptionState.throwIfNeeded();
32 return; 37 return;
33 } 38 }
34 } 39 }
35 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan ce().create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate()); 40 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan ce().create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate());
36 if (exceptionState.throwIfNeeded()) 41 if (exceptionState.throwIfNeeded())
37 return; 42 return;
38 // FIXME: Only pass context/exceptionState if instance really requires it. 43 // FIXME: Only pass context/exceptionState if instance really requires it.
39 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); 44 ExecutionContext* context = currentExecutionContext(info.GetIsolate());
40 instance->postMessage(context, message.release(), &ports, exceptionState); 45 instance->postMessage(context, message.release(), &ports, exceptionState);
41 exceptionState.throwIfNeeded(); 46 exceptionState.throwIfNeeded();
42 } 47 }
43 48
44 } // namespace blink 49 } // namespace blink
45 50
46 #endif // PostMessage_h 51 #endif // PostMessage_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698