| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2011 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // to hold on to them. | 254 // to hold on to them. |
| 255 DOMWindow* window = V8Window::toNative(info.Holder()); | 255 DOMWindow* window = V8Window::toNative(info.Holder()); |
| 256 DOMWindow* source = activeDOMWindow(); | 256 DOMWindow* source = activeDOMWindow(); |
| 257 | 257 |
| 258 // If called directly by WebCore we don't have a calling context. | 258 // If called directly by WebCore we don't have a calling context. |
| 259 if (!source) { | 259 if (!source) { |
| 260 throwUninformativeAndGenericTypeError(info.GetIsolate()); | 260 throwUninformativeAndGenericTypeError(info.GetIsolate()); |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 | 263 |
| 264 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); |
| 264 // This function has variable arguments and can be: | 265 // This function has variable arguments and can be: |
| 265 // Per current spec: | 266 // Per current spec: |
| 266 // postMessage(message, targetOrigin) | 267 // postMessage(message, targetOrigin) |
| 267 // postMessage(message, targetOrigin, {sequence of transferrables}) | 268 // postMessage(message, targetOrigin, {sequence of transferrables}) |
| 268 // Legacy non-standard implementations in webkit allowed: | 269 // Legacy non-standard implementations in webkit allowed: |
| 269 // postMessage(message, {sequence of transferrables}, targetOrigin); | 270 // postMessage(message, {sequence of transferrables}, targetOrigin); |
| 270 MessagePortArray portArray; | 271 MessagePortArray portArray; |
| 271 ArrayBufferArray arrayBufferArray; | 272 ArrayBufferArray arrayBufferArray; |
| 272 int targetOriginArgIndex = 1; | 273 int targetOriginArgIndex = 1; |
| 273 if (info.Length() > 2) { | 274 if (info.Length() > 2) { |
| 274 int transferablesArgIndex = 2; | 275 int transferablesArgIndex = 2; |
| 275 if (isLegacyTargetOriginDesignation(info[2])) { | 276 if (isLegacyTargetOriginDesignation(info[2])) { |
| 276 targetOriginArgIndex = 2; | 277 targetOriginArgIndex = 2; |
| 277 transferablesArgIndex = 1; | 278 transferablesArgIndex = 1; |
| 278 } | 279 } |
| 279 bool notASequence = false; | 280 if (!extractTransferables(info[transferablesArgIndex], transferablesArgI
ndex, portArray, arrayBufferArray, exceptionState, info.GetIsolate())) { |
| 280 if (!extractTransferables(info[transferablesArgIndex], portArray, arrayB
ufferArray, notASequence, info.GetIsolate())) { | 281 exceptionState.throwIfNeeded(); |
| 281 if (notASequence) | |
| 282 throwTypeError(ExceptionMessages::failedToExecute("postMessage",
"Window", ExceptionMessages::notAnArrayTypeArgumentOrValue(transferablesArgInde
x + 1)), info.GetIsolate()); | |
| 283 return; | 282 return; |
| 284 } | 283 } |
| 285 } | 284 } |
| 286 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe
ck>, targetOrigin, info[targetOriginArgIndex]); | 285 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe
ck>, targetOrigin, info[targetOriginArgIndex]); |
| 287 | 286 |
| 288 bool didThrow = false; | 287 RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0
], &portArray, &arrayBufferArray, exceptionState, info.GetIsolate()); |
| 289 RefPtr<SerializedScriptValue> message = | 288 if (exceptionState.throwIfNeeded()) |
| 290 SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, di
dThrow, info.GetIsolate()); | |
| 291 if (didThrow) | |
| 292 return; | 289 return; |
| 293 | 290 |
| 294 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); | |
| 295 window->postMessage(message.release(), &portArray, targetOrigin, source, exc
eptionState); | 291 window->postMessage(message.release(), &portArray, targetOrigin, source, exc
eptionState); |
| 296 exceptionState.throwIfNeeded(); | 292 exceptionState.throwIfNeeded(); |
| 297 } | 293 } |
| 298 | 294 |
| 299 // FIXME(fqian): returning string is cheating, and we should | 295 // FIXME(fqian): returning string is cheating, and we should |
| 300 // fix this by calling toString function on the receiver. | 296 // fix this by calling toString function on the receiver. |
| 301 // However, V8 implements toString in JavaScript, which requires | 297 // However, V8 implements toString in JavaScript, which requires |
| 302 // switching context of receiver. I consider it is dangerous. | 298 // switching context of receiver. I consider it is dangerous. |
| 303 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) | 299 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) |
| 304 { | 300 { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 v8::Handle<v8::Context> context = frame->script().currentWorldContext(); | 556 v8::Handle<v8::Context> context = frame->script().currentWorldContext(); |
| 561 if (context.IsEmpty()) | 557 if (context.IsEmpty()) |
| 562 return v8Undefined(); | 558 return v8Undefined(); |
| 563 | 559 |
| 564 v8::Handle<v8::Object> global = context->Global(); | 560 v8::Handle<v8::Object> global = context->Global(); |
| 565 ASSERT(!global.IsEmpty()); | 561 ASSERT(!global.IsEmpty()); |
| 566 return global; | 562 return global; |
| 567 } | 563 } |
| 568 | 564 |
| 569 } // namespace WebCore | 565 } // namespace WebCore |
| OLD | NEW |