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