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 2205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 Vector<v8::Handle<v8::Value> > m_objectPool; | 2216 Vector<v8::Handle<v8::Value> > m_objectPool; |
2217 Vector<uint32_t> m_openCompositeReferenceStack; | 2217 Vector<uint32_t> m_openCompositeReferenceStack; |
2218 MessagePortArray* m_transferredMessagePorts; | 2218 MessagePortArray* m_transferredMessagePorts; |
2219 ArrayBufferContentsArray* m_arrayBufferContents; | 2219 ArrayBufferContentsArray* m_arrayBufferContents; |
2220 Vector<v8::Handle<v8::Object> > m_arrayBuffers; | 2220 Vector<v8::Handle<v8::Object> > m_arrayBuffers; |
2221 uint32_t m_version; | 2221 uint32_t m_version; |
2222 }; | 2222 }; |
2223 | 2223 |
2224 } // namespace | 2224 } // namespace |
2225 | 2225 |
2226 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, boo
l& didThrow) | |
2227 { | |
2228 return create(value, messagePorts, arrayBuffers, didThrow, v8::Isolate::GetC
urrent()); | |
2229 } | |
2230 | |
2231 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, boo
l& didThrow, v8::Isolate* isolate) | 2226 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, boo
l& didThrow, v8::Isolate* isolate) |
2232 { | 2227 { |
2233 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers,
didThrow, isolate)); | 2228 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers,
didThrow, isolate)); |
2234 } | 2229 } |
2235 | 2230 |
2236 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value) | |
2237 { | |
2238 return create(value, v8::Isolate::GetCurrent()); | |
2239 } | |
2240 | |
2241 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value, v8::Isolate* isolate) | 2231 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
alue> value, v8::Isolate* isolate) |
2242 { | 2232 { |
2243 bool didThrow; | 2233 bool didThrow; |
2244 return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate)); | 2234 return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate)); |
2245 } | 2235 } |
2246 | 2236 |
| 2237 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti
ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 2238 { |
| 2239 bool didThrow; |
| 2240 return adoptRef(new SerializedScriptValue(value, 0, 0, didThrow, isolate, Do
NotThrowExceptions)); |
| 2241 } |
| 2242 |
2247 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St
ring& data) | 2243 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St
ring& data) |
2248 { | 2244 { |
2249 return adoptRef(new SerializedScriptValue(data)); | 2245 return adoptRef(new SerializedScriptValue(data)); |
2250 } | 2246 } |
2251 | 2247 |
2252 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con
st Vector<uint8_t>& data) | 2248 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con
st Vector<uint8_t>& data) |
2253 { | 2249 { |
2254 // Decode wire data from big endian to host byte order. | 2250 // Decode wire data from big endian to host byte order. |
2255 ASSERT(!(data.size() % sizeof(UChar))); | 2251 ASSERT(!(data.size() % sizeof(UChar))); |
2256 size_t length = data.size() / sizeof(UChar); | 2252 size_t length = data.size() / sizeof(UChar); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2418 return nullptr; | 2414 return nullptr; |
2419 } | 2415 } |
2420 | 2416 |
2421 neuterBinding(arrayBuffers[i].get()); | 2417 neuterBinding(arrayBuffers[i].get()); |
2422 for (size_t j = 0; j < neuteredViews.size(); j++) | 2418 for (size_t j = 0; j < neuteredViews.size(); j++) |
2423 neuterBinding(neuteredViews[j].get()); | 2419 neuterBinding(neuteredViews[j].get()); |
2424 } | 2420 } |
2425 return contents.release(); | 2421 return contents.release(); |
2426 } | 2422 } |
2427 | 2423 |
2428 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag
ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is
olate* isolate) | 2424 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag
ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is
olate* isolate, ExceptionPolicy policy) |
2429 : m_externallyAllocatedMemory(0) | 2425 : m_externallyAllocatedMemory(0) |
2430 { | 2426 { |
2431 didThrow = false; | 2427 didThrow = false; |
2432 Writer writer(isolate); | 2428 Writer writer(isolate); |
2433 Serializer::Status status; | 2429 Serializer::Status status; |
2434 { | 2430 { |
2435 v8::TryCatch tryCatch; | 2431 v8::TryCatch tryCatch; |
2436 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr
yCatch, isolate); | 2432 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr
yCatch, isolate); |
2437 status = serializer.serialize(value); | 2433 status = serializer.serialize(value); |
2438 if (status == Serializer::JSException) { | 2434 if (status == Serializer::JSException) { |
| 2435 didThrow = true; |
2439 // If there was a JS exception thrown, re-throw it. | 2436 // If there was a JS exception thrown, re-throw it. |
2440 didThrow = true; | 2437 if (policy == ThrowExceptions) |
2441 tryCatch.ReThrow(); | 2438 tryCatch.ReThrow(); |
2442 return; | 2439 return; |
2443 } | 2440 } |
2444 } | 2441 } |
2445 switch (status) { | 2442 switch (status) { |
2446 case Serializer::InputError: | 2443 case Serializer::InputError: |
2447 case Serializer::DataCloneError: | 2444 case Serializer::DataCloneError: |
2448 // If there was an input error, throw a new exception outside | 2445 // If there was an input error, throw a new exception outside |
2449 // of the TryCatch scope. | 2446 // of the TryCatch scope. |
2450 didThrow = true; | 2447 didThrow = true; |
2451 setDOMException(DataCloneError, isolate); | 2448 if (policy == ThrowExceptions) |
| 2449 setDOMException(DataCloneError, isolate); |
2452 return; | 2450 return; |
2453 case Serializer::InvalidStateError: | 2451 case Serializer::InvalidStateError: |
2454 didThrow = true; | 2452 didThrow = true; |
2455 setDOMException(InvalidStateError, isolate); | 2453 if (policy == ThrowExceptions) |
| 2454 setDOMException(InvalidStateError, isolate); |
2456 return; | 2455 return; |
2457 case Serializer::JSFailure: | 2456 case Serializer::JSFailure: |
2458 // If there was a JS failure (but no exception), there's not | 2457 // If there was a JS failure (but no exception), there's not |
2459 // much we can do except for unwinding the C++ stack by | 2458 // much we can do except for unwinding the C++ stack by |
2460 // pretending there was a JS exception. | 2459 // pretending there was a JS exception. |
2461 didThrow = true; | 2460 didThrow = true; |
2462 return; | 2461 return; |
2463 case Serializer::Success: | 2462 case Serializer::Success: |
2464 m_data = String(StringImpl::adopt(writer.data())).isolatedCopy(); | 2463 m_data = String(StringImpl::adopt(writer.data())).isolatedCopy(); |
2465 if (arrayBuffers && arrayBuffers->size()) | 2464 if (arrayBuffers && arrayBuffers->size()) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2523 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); | 2522 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); |
2524 } | 2523 } |
2525 } | 2524 } |
2526 | 2525 |
2527 uint32_t SerializedScriptValue::wireFormatVersion() | 2526 uint32_t SerializedScriptValue::wireFormatVersion() |
2528 { | 2527 { |
2529 return WebCore::wireFormatVersion; | 2528 return WebCore::wireFormatVersion; |
2530 } | 2529 } |
2531 | 2530 |
2532 } // namespace WebCore | 2531 } // namespace WebCore |
OLD | NEW |