Chromium Code Reviews| Index: Source/bindings/v8/custom/V8ServiceWorkerCustom.cpp |
| diff --git a/Source/bindings/v8/custom/V8ServiceWorkerCustom.cpp b/Source/bindings/v8/custom/V8ServiceWorkerCustom.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..76ae831623153386024f70b3d673097af5250d16 |
| --- /dev/null |
| +++ b/Source/bindings/v8/custom/V8ServiceWorkerCustom.cpp |
| @@ -0,0 +1,38 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "V8ServiceWorker.h" |
| + |
| +#include "bindings/v8/ExceptionMessages.h" |
| +#include "bindings/v8/ExceptionState.h" |
| +#include "bindings/v8/SerializedScriptValue.h" |
| +#include "bindings/v8/V8Binding.h" |
| +#include "core/dom/MessagePort.h" |
| +#include "modules/serviceworkers/ServiceWorker.h" |
| +#include "wtf/ArrayBuffer.h" |
| + |
| +namespace WebCore { |
| + |
| +void V8ServiceWorker::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| +{ |
| + ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "ServiceWorker", info.Holder(), info.GetIsolate()); |
| + ServiceWorker* worker = V8ServiceWorker::toNative(info.Holder()); |
| + MessagePortArray ports; |
| + ArrayBufferArray arrayBuffers; |
| + if (info.Length() > 1) { |
| + const int transferablesArgIndex = 1; |
| + if (!SerializedScriptValue::extractTransferables(info[transferablesArgIndex], transferablesArgIndex, ports, arrayBuffers, exceptionState, info.GetIsolate())) { |
| + exceptionState.throwIfNeeded(); |
| + return; |
| + } |
| + } |
| + RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &ports, &arrayBuffers, exceptionState, info.GetIsolate()); |
| + if (exceptionState.throwIfNeeded()) |
| + return; |
| + worker->postMessage(message.release(), &ports, exceptionState); |
| + exceptionState.throwIfNeeded(); |
|
kinuko
2014/03/11 07:13:36
(It's a bit sad that we seem to have mostly same c
jsbell
2014/03/11 15:56:41
Yep. I'll move the common code into V8Binding.cpp
jsbell
2014/03/11 20:10:51
I gave this a shot, but it ended up not saving man
|
| +} |
| + |
| +} // namespace WebCore |