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 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 } | 2403 } |
2404 ASSERT_NOT_REACHED(); | 2404 ASSERT_NOT_REACHED(); |
2405 } | 2405 } |
2406 | 2406 |
2407 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 2407 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
2408 : m_externallyAllocatedMemory(0) | 2408 : m_externallyAllocatedMemory(0) |
2409 { | 2409 { |
2410 m_data = wireData.isolatedCopy(); | 2410 m_data = wireData.isolatedCopy(); |
2411 } | 2411 } |
2412 | 2412 |
2413 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
gePorts, v8::Isolate* isolate) | 2413 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa
gePorts) |
| 2414 { |
| 2415 return deserialize(v8::Isolate::GetCurrent(), messagePorts); |
| 2416 } |
| 2417 |
| 2418 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M
essagePortArray* messagePorts) |
2414 { | 2419 { |
2415 if (!m_data.impl()) | 2420 if (!m_data.impl()) |
2416 return v8NullWithCheck(isolate); | 2421 return v8NullWithCheck(isolate); |
2417 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2422 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); |
2418 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()),
2 * m_data.length(), isolate); | 2423 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()),
2 * m_data.length(), isolate); |
2419 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); | 2424 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g
et()); |
2420 return deserializer.deserialize(); | 2425 return deserializer.deserialize(); |
2421 } | 2426 } |
2422 | 2427 |
2423 #if ENABLE(INSPECTOR) | 2428 #if ENABLE(INSPECTOR) |
2424 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
ate, v8::Isolate* isolate) | 2429 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt
ate) |
2425 { | 2430 { |
2426 v8::HandleScope handleScope; | 2431 v8::HandleScope handleScope; |
2427 v8::Context::Scope contextScope(scriptState->context()); | 2432 v8::Context::Scope contextScope(scriptState->context()); |
2428 | 2433 |
2429 return ScriptValue(deserialize(0, isolate)); | 2434 return ScriptValue(deserialize(scriptState->isolate())); |
2430 } | 2435 } |
2431 #endif | 2436 #endif |
2432 | 2437 |
2433 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 2438 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
2434 { | 2439 { |
2435 if (m_externallyAllocatedMemory) | 2440 if (m_externallyAllocatedMemory) |
2436 return; | 2441 return; |
2437 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); | 2442 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); |
2438 v8::V8::AdjustAmountOfExternalAllocatedMemory(m_externallyAllocatedMemory); | 2443 v8::V8::AdjustAmountOfExternalAllocatedMemory(m_externallyAllocatedMemory); |
2439 } | 2444 } |
2440 | 2445 |
2441 SerializedScriptValue::~SerializedScriptValue() | 2446 SerializedScriptValue::~SerializedScriptValue() |
2442 { | 2447 { |
2443 // If the allocated memory was not registered before, then this class is lik
ely | 2448 // If the allocated memory was not registered before, then this class is lik
ely |
2444 // used in a context other then Worker's onmessage environment and the prese
nce of | 2449 // used in a context other then Worker's onmessage environment and the prese
nce of |
2445 // current v8 context is not guaranteed. Avoid calling v8 then. | 2450 // current v8 context is not guaranteed. Avoid calling v8 then. |
2446 if (m_externallyAllocatedMemory) { | 2451 if (m_externallyAllocatedMemory) { |
2447 ASSERT(v8::Isolate::GetCurrent()); | 2452 ASSERT(v8::Isolate::GetCurrent()); |
2448 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); | 2453 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); |
2449 } | 2454 } |
2450 } | 2455 } |
2451 | 2456 |
2452 uint32_t SerializedScriptValue::wireFormatVersion() | 2457 uint32_t SerializedScriptValue::wireFormatVersion() |
2453 { | 2458 { |
2454 return WebCore::wireFormatVersion; | 2459 return WebCore::wireFormatVersion; |
2455 } | 2460 } |
2456 | 2461 |
2457 } // namespace WebCore | 2462 } // namespace WebCore |
OLD | NEW |