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
3 // found in the LICENSE file.
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/SerializedScriptValue.h"
10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/core/v8/V8BindingMacros.h"
12 #include "core/dom/MessagePort.h"
13 #include "wtf/ArrayBuffer.h"
18 class ExecutionContext;
20 // FIXME: This should be auto-generated by a code generator template.
22 void postMessageMethodCommon(const char* interfaceName, Type* instance, const v8::FunctionCallbackInfo<v8::Value>& info)
24 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", interfaceName, info.Holder(), info.GetIsolate());
25 MessagePortArray ports;
26 ArrayBufferArray arrayBuffers;
27 if (info.Length() > 1) {
28 const int transferablesArgIndex = 1;
29 if (!SerializedScriptValue::extractTransferables(info[transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionState, info.GetIsolate())) {
30 exceptionState.throwIfNeeded();
34 RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate());
35 if (exceptionState.throwIfNeeded())
37 // FIXME: Only pass context/exceptionState if instance really requires it.
38 ExecutionContext* context = currentExecutionContext(info.GetIsolate());
39 instance->postMessage(context, message.release(), &ports, exceptionState);
40 exceptionState.throwIfNeeded();
45 #endif // PostMessage_h