| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 23 matching lines...) Expand all Loading... |
| 34 #include "V8Blob.h" | 34 #include "V8Blob.h" |
| 35 #include "V8DOMFileSystem.h" | 35 #include "V8DOMFileSystem.h" |
| 36 #include "V8File.h" | 36 #include "V8File.h" |
| 37 #include "V8FileList.h" | 37 #include "V8FileList.h" |
| 38 #include "V8ImageData.h" | 38 #include "V8ImageData.h" |
| 39 #include "V8MessagePort.h" | 39 #include "V8MessagePort.h" |
| 40 #include "bindings/v8/ExceptionState.h" | 40 #include "bindings/v8/ExceptionState.h" |
| 41 #include "bindings/v8/ScriptScope.h" | 41 #include "bindings/v8/ScriptScope.h" |
| 42 #include "bindings/v8/ScriptState.h" | 42 #include "bindings/v8/ScriptState.h" |
| 43 #include "bindings/v8/V8Binding.h" | 43 #include "bindings/v8/V8Binding.h" |
| 44 #include "bindings/v8/V8Utilities.h" | |
| 45 #include "bindings/v8/WorkerScriptController.h" | 44 #include "bindings/v8/WorkerScriptController.h" |
| 46 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 45 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| 47 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 46 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
| 48 #include "bindings/v8/custom/V8DataViewCustom.h" | 47 #include "bindings/v8/custom/V8DataViewCustom.h" |
| 49 #include "bindings/v8/custom/V8Float32ArrayCustom.h" | 48 #include "bindings/v8/custom/V8Float32ArrayCustom.h" |
| 50 #include "bindings/v8/custom/V8Float64ArrayCustom.h" | 49 #include "bindings/v8/custom/V8Float64ArrayCustom.h" |
| 51 #include "bindings/v8/custom/V8Int16ArrayCustom.h" | 50 #include "bindings/v8/custom/V8Int16ArrayCustom.h" |
| 52 #include "bindings/v8/custom/V8Int32ArrayCustom.h" | 51 #include "bindings/v8/custom/V8Int32ArrayCustom.h" |
| 53 #include "bindings/v8/custom/V8Int8ArrayCustom.h" | 52 #include "bindings/v8/custom/V8Int8ArrayCustom.h" |
| 54 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" | 53 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" |
| (...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2433 // unicode characters are encoded as UTF-8 with two code units per UChar. | 2432 // unicode characters are encoded as UTF-8 with two code units per UChar. |
| 2434 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()
), 2 * m_data.length(), isolate, m_blobDataHandles); | 2433 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16()
), 2 * m_data.length(), isolate, m_blobDataHandles); |
| 2435 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); | 2434 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); |
| 2436 | 2435 |
| 2437 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. | 2436 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. |
| 2438 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. | 2437 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. |
| 2439 RefPtr<SerializedScriptValue> protect(this); | 2438 RefPtr<SerializedScriptValue> protect(this); |
| 2440 return deserializer.deserialize(); | 2439 return deserializer.deserialize(); |
| 2441 } | 2440 } |
| 2442 | 2441 |
| 2442 bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int
argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, Excepti
onState& exceptionState, v8::Isolate* isolate) |
| 2443 { |
| 2444 if (isUndefinedOrNull(value)) { |
| 2445 ports.resize(0); |
| 2446 arrayBuffers.resize(0); |
| 2447 return true; |
| 2448 } |
| 2449 |
| 2450 uint32_t length = 0; |
| 2451 if (value->IsArray()) { |
| 2452 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); |
| 2453 length = array->Length(); |
| 2454 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
| 2455 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO
rValue(argumentIndex + 1)); |
| 2456 return false; |
| 2457 } |
| 2458 |
| 2459 v8::Local<v8::Object> transferrables = v8::Local<v8::Object>::Cast(value); |
| 2460 |
| 2461 // Validate the passed array of transferrables. |
| 2462 for (unsigned i = 0; i < length; ++i) { |
| 2463 v8::Local<v8::Value> transferrable = transferrables->Get(i); |
| 2464 // Validation of non-null objects, per HTML5 spec 10.3.3. |
| 2465 if (isUndefinedOrNull(transferrable)) { |
| 2466 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ?
"'undefined'" : "'null'") + " value."); |
| 2467 return false; |
| 2468 } |
| 2469 // Validation of Objects implementing an interface, per WebIDL spec 4.1.
15. |
| 2470 if (V8MessagePort::hasInstance(transferrable, isolate)) { |
| 2471 RefPtr<MessagePort> port = V8MessagePort::toNative(v8::Handle<v8::Ob
ject>::Cast(transferrable)); |
| 2472 // Check for duplicate MessagePorts. |
| 2473 if (ports.contains(port)) { |
| 2474 exceptionState.throwDOMException(DataCloneError, "Message port a
t index " + String::number(i) + " is a duplicate of an earlier port."); |
| 2475 return false; |
| 2476 } |
| 2477 ports.append(port.release()); |
| 2478 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { |
| 2479 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(v8::Handle
<v8::Object>::Cast(transferrable)); |
| 2480 if (arrayBuffers.contains(arrayBuffer)) { |
| 2481 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); |
| 2482 return false; |
| 2483 } |
| 2484 arrayBuffers.append(arrayBuffer.release()); |
| 2485 } else { |
| 2486 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " does not have a transferable type."); |
| 2487 return false; |
| 2488 } |
| 2489 } |
| 2490 return true; |
| 2491 } |
| 2492 |
| 2443 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 2493 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
| 2444 { | 2494 { |
| 2445 if (m_externallyAllocatedMemory) | 2495 if (m_externallyAllocatedMemory) |
| 2446 return; | 2496 return; |
| 2447 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); | 2497 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); |
| 2448 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); | 2498 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); |
| 2449 } | 2499 } |
| 2450 | 2500 |
| 2451 SerializedScriptValue::~SerializedScriptValue() | 2501 SerializedScriptValue::~SerializedScriptValue() |
| 2452 { | 2502 { |
| 2453 // If the allocated memory was not registered before, then this class is lik
ely | 2503 // If the allocated memory was not registered before, then this class is lik
ely |
| 2454 // used in a context other then Worker's onmessage environment and the prese
nce of | 2504 // used in a context other then Worker's onmessage environment and the prese
nce of |
| 2455 // current v8 context is not guaranteed. Avoid calling v8 then. | 2505 // current v8 context is not guaranteed. Avoid calling v8 then. |
| 2456 if (m_externallyAllocatedMemory) { | 2506 if (m_externallyAllocatedMemory) { |
| 2457 ASSERT(v8::Isolate::GetCurrent()); | 2507 ASSERT(v8::Isolate::GetCurrent()); |
| 2458 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 2508 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
| 2459 } | 2509 } |
| 2460 } | 2510 } |
| 2461 | 2511 |
| 2462 } // namespace WebCore | 2512 } // namespace WebCore |
| OLD | NEW |