void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate()); if (UNLIKELY(info.Length() < 2)) { setMinimumArityTypeError(exceptionState, 2, info.Length()); exceptionState.throwIfNeeded(); return; } // None of these need to be RefPtr because info and context are guaranteed // to hold on to them. DOMWindow* window = V8Window::toImpl(info.Holder()); LocalDOMWindow* source = callingDOMWindow(info.GetIsolate()); ASSERT(window); UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseCounter::WindowPostMessage); // If called directly by WebCore we don't have a calling context. if (!source) { exceptionState.throwTypeError("No active calling context exists."); exceptionState.throwIfNeeded(); return; } // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); OwnPtrWillBeRawPtr<MessagePortArray> portArray = adoptPtrWillBeNoop(new MessagePortArray); ArrayBufferArray arrayBufferArray; int targetOriginArgIndex = 1; if (info.Length() > 2) { int transferablesArgIndex = 2; if (isLegacyTargetOriginDesignation(info[2])) { UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument); targetOriginArgIndex = 2; transferablesArgIndex = 1; } if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info[transferablesArgIndex], transferablesArgIndex, *portArray, arrayBufferArray, exceptionState)) { exceptionState.throwIfNeeded(); return; } } TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOrigin, info[targetOriginArgIndex]); RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instance().create(info.GetIsolate(), info[0], portArray.get(), &arrayBufferArray, exceptionState); if (exceptionState.throwIfNeeded()) return; window->postMessage(message.release(), portArray.get(), targetOrigin, source, exceptionState); exceptionState.throwIfNeeded(); }
void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { // None of these need to be RefPtr because info and context are guaranteed // to hold on to them. DOMWindow* window = V8Window::toNative(info.Holder()); DOMWindow* source = activeDOMWindow(); // If called directly by WebCore we don't have a calling context. if (!source) { throwUninformativeAndGenericTypeError(info.GetIsolate()); return; } // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); MessagePortArray portArray; ArrayBufferArray arrayBufferArray; int targetOriginArgIndex = 1; if (info.Length() > 2) { int transferablesArgIndex = 2; if (isLegacyTargetOriginDesignation(info[2])) { targetOriginArgIndex = 2; transferablesArgIndex = 1; } bool notASequence = false; if (!extractTransferables(info[transferablesArgIndex], portArray, arrayBufferArray, notASequence, info.GetIsolate())) { if (notASequence) throwTypeError(ExceptionMessages::failedToExecute("postMessage", "Window", ExceptionMessages::notAnArrayTypeArgumentOrValue(transferablesArgIndex + 1)), info.GetIsolate()); return; } } V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, targetOrigin, info[targetOriginArgIndex]); bool didThrow = false; RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, didThrow, info.GetIsolate()); if (didThrow) return; ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate()); window->postMessage(message.release(), &portArray, targetOrigin, source, exceptionState); exceptionState.throwIfNeeded(); }
void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { // None of these need to be RefPtr because info and context are guaranteed // to hold on to them. LocalDOMWindow* window = V8Window::toNative(info.Holder()); LocalDOMWindow* source = callingDOMWindow(info.GetIsolate()); ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate()); // If called directly by WebCore we don't have a calling context. if (!source) { exceptionState.throwTypeError("No active calling context exists."); exceptionState.throwIfNeeded(); return; } // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); MessagePortArray portArray; ArrayBufferArray arrayBufferArray; int targetOriginArgIndex = 1; if (info.Length() > 2) { int transferablesArgIndex = 2; if (isLegacyTargetOriginDesignation(info[2])) { targetOriginArgIndex = 2; transferablesArgIndex = 1; } if (!SerializedScriptValue::extractTransferables(info[transferablesArgIndex], transferablesArgIndex, portArray, arrayBufferArray, exceptionState, info.GetIsolate())) { exceptionState.throwIfNeeded(); return; } } TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOrigin, info[targetOriginArgIndex]); RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, exceptionState, info.GetIsolate()); if (exceptionState.throwIfNeeded()) return; window->postMessage(message.release(), &portArray, targetOrigin, source, exceptionState); exceptionState.throwIfNeeded(); }