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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 static bool shouldCheckForCycles(int depth) | 233 static bool shouldCheckForCycles(int depth) |
234 { | 234 { |
235 ASSERT(depth >= 0); | 235 ASSERT(depth >= 0); |
236 // Since we are not required to spot the cycle as soon as it | 236 // Since we are not required to spot the cycle as soon as it |
237 // happens we can check for cycles only when the current depth | 237 // happens we can check for cycles only when the current depth |
238 // is a power of two. | 238 // is a power of two. |
239 return !(depth & (depth - 1)); | 239 return !(depth & (depth - 1)); |
240 } | 240 } |
241 | 241 |
242 // Increment this for each incompatible change to the wire format. | |
243 // Version 2: Added StringUCharTag for UChar v8 strings. | |
244 static const uint32_t wireFormatVersion = 2; | |
245 | |
246 static const int maxDepth = 20000; | 242 static const int maxDepth = 20000; |
247 | 243 |
248 // VarInt encoding constants. | 244 // VarInt encoding constants. |
249 static const int varIntShift = 7; | 245 static const int varIntShift = 7; |
250 static const int varIntMask = (1 << varIntShift) - 1; | 246 static const int varIntMask = (1 << varIntShift) - 1; |
251 | 247 |
252 // ZigZag encoding helps VarInt encoding stay small for negative | 248 // ZigZag encoding helps VarInt encoding stay small for negative |
253 // numbers with small absolute values. | 249 // numbers with small absolute values. |
254 class ZigZag { | 250 class ZigZag { |
255 public: | 251 public: |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 { | 355 { |
360 // Uses UTF8 encoding so we can read it back as either V8 or | 356 // Uses UTF8 encoding so we can read it back as either V8 or |
361 // WebCore string. | 357 // WebCore string. |
362 append(StringTag); | 358 append(StringTag); |
363 doWriteWebCoreString(string); | 359 doWriteWebCoreString(string); |
364 } | 360 } |
365 | 361 |
366 void writeVersion() | 362 void writeVersion() |
367 { | 363 { |
368 append(VersionTag); | 364 append(VersionTag); |
369 doWriteUint32(wireFormatVersion); | 365 doWriteUint32(SerializedScriptValue::wireFormatVersion); |
370 } | 366 } |
371 | 367 |
372 void writeInt32(int32_t value) | 368 void writeInt32(int32_t value) |
373 { | 369 { |
374 append(Int32Tag); | 370 append(Int32Tag); |
375 doWriteUint32(ZigZag::encode(static_cast<uint32_t>(value))); | 371 doWriteUint32(ZigZag::encode(static_cast<uint32_t>(value))); |
376 } | 372 } |
377 | 373 |
378 void writeUint32(uint32_t value) | 374 void writeUint32(uint32_t value) |
379 { | 375 { |
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 : m_reader(reader) | 1973 : m_reader(reader) |
1978 , m_transferredMessagePorts(messagePorts) | 1974 , m_transferredMessagePorts(messagePorts) |
1979 , m_arrayBufferContents(arrayBufferContents) | 1975 , m_arrayBufferContents(arrayBufferContents) |
1980 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) | 1976 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) |
1981 , m_version(0) | 1977 , m_version(0) |
1982 { | 1978 { |
1983 } | 1979 } |
1984 | 1980 |
1985 v8::Handle<v8::Value> deserialize() | 1981 v8::Handle<v8::Value> deserialize() |
1986 { | 1982 { |
1987 if (!m_reader.readVersion(m_version) || m_version > wireFormatVersion) | 1983 if (!m_reader.readVersion(m_version) || m_version > SerializedScriptValu
e::wireFormatVersion) |
1988 return v8NullWithCheck(m_reader.getIsolate()); | 1984 return v8NullWithCheck(m_reader.getIsolate()); |
1989 m_reader.setVersion(m_version); | 1985 m_reader.setVersion(m_version); |
1990 v8::HandleScope scope(m_reader.getIsolate()); | 1986 v8::HandleScope scope(m_reader.getIsolate()); |
1991 while (!m_reader.isEof()) { | 1987 while (!m_reader.isEof()) { |
1992 if (!doDeserialize()) | 1988 if (!doDeserialize()) |
1993 return v8NullWithCheck(m_reader.getIsolate()); | 1989 return v8NullWithCheck(m_reader.getIsolate()); |
1994 } | 1990 } |
1995 if (stackDepth() != 1 || m_openCompositeReferenceStack.size()) | 1991 if (stackDepth() != 1 || m_openCompositeReferenceStack.size()) |
1996 return v8NullWithCheck(m_reader.getIsolate()); | 1992 return v8NullWithCheck(m_reader.getIsolate()); |
1997 v8::Handle<v8::Value> result = scope.Close(element(0)); | 1993 v8::Handle<v8::Value> result = scope.Close(element(0)); |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 { | 2524 { |
2529 // If the allocated memory was not registered before, then this class is lik
ely | 2525 // If the allocated memory was not registered before, then this class is lik
ely |
2530 // used in a context other then Worker's onmessage environment and the prese
nce of | 2526 // used in a context other then Worker's onmessage environment and the prese
nce of |
2531 // current v8 context is not guaranteed. Avoid calling v8 then. | 2527 // current v8 context is not guaranteed. Avoid calling v8 then. |
2532 if (m_externallyAllocatedMemory) { | 2528 if (m_externallyAllocatedMemory) { |
2533 ASSERT(v8::Isolate::GetCurrent()); | 2529 ASSERT(v8::Isolate::GetCurrent()); |
2534 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); | 2530 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); |
2535 } | 2531 } |
2536 } | 2532 } |
2537 | 2533 |
2538 uint32_t SerializedScriptValue::wireFormatVersion() | |
2539 { | |
2540 return WebCore::wireFormatVersion; | |
2541 } | |
2542 | |
2543 } // namespace WebCore | 2534 } // namespace WebCore |
OLD | NEW |