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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 } | 1271 } |
1272 | 1272 |
1273 void writeBooleanObject(v8::Handle<v8::Value> value) | 1273 void writeBooleanObject(v8::Handle<v8::Value> value) |
1274 { | 1274 { |
1275 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
>(); | 1275 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject
>(); |
1276 m_writer.writeBooleanObject(booleanObject->ValueOf()); | 1276 m_writer.writeBooleanObject(booleanObject->ValueOf()); |
1277 } | 1277 } |
1278 | 1278 |
1279 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) | 1279 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) |
1280 { | 1280 { |
1281 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1281 Blob* blob = V8Blob::toImpl(value.As<v8::Object>()); |
1282 if (!blob) | 1282 if (!blob) |
1283 return 0; | 1283 return 0; |
1284 if (blob->hasBeenClosed()) | 1284 if (blob->hasBeenClosed()) |
1285 return handleError(DataCloneError, "A Blob object has been closed, a
nd could therefore not be cloned.", next); | 1285 return handleError(DataCloneError, "A Blob object has been closed, a
nd could therefore not be cloned.", next); |
1286 int blobIndex = -1; | 1286 int blobIndex = -1; |
1287 m_blobDataHandles.set(blob->uuid(), blob->blobDataHandle()); | 1287 m_blobDataHandles.set(blob->uuid(), blob->blobDataHandle()); |
1288 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex)
) | 1288 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex)
) |
1289 m_writer.writeBlobIndex(blobIndex); | 1289 m_writer.writeBlobIndex(blobIndex); |
1290 else | 1290 else |
1291 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); | 1291 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); |
1292 return 0; | 1292 return 0; |
1293 } | 1293 } |
1294 | 1294 |
1295 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1295 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
1296 { | 1296 { |
1297 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1297 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>()); |
1298 if (!fs) | 1298 if (!fs) |
1299 return 0; | 1299 return 0; |
1300 if (!fs->clonable()) | 1300 if (!fs->clonable()) |
1301 return handleError(DataCloneError, "A FileSystem object could not be
cloned.", next); | 1301 return handleError(DataCloneError, "A FileSystem object could not be
cloned.", next); |
1302 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); | 1302 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); |
1303 return 0; | 1303 return 0; |
1304 } | 1304 } |
1305 | 1305 |
1306 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) | 1306 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) |
1307 { | 1307 { |
1308 File* file = V8File::toNative(value.As<v8::Object>()); | 1308 File* file = V8File::toImpl(value.As<v8::Object>()); |
1309 if (!file) | 1309 if (!file) |
1310 return 0; | 1310 return 0; |
1311 if (file->hasBeenClosed()) | 1311 if (file->hasBeenClosed()) |
1312 return handleError(DataCloneError, "A File object has been closed, a
nd could therefore not be cloned.", next); | 1312 return handleError(DataCloneError, "A File object has been closed, a
nd could therefore not be cloned.", next); |
1313 int blobIndex = -1; | 1313 int blobIndex = -1; |
1314 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); | 1314 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); |
1315 if (appendFileInfo(file, &blobIndex)) { | 1315 if (appendFileInfo(file, &blobIndex)) { |
1316 ASSERT(blobIndex >= 0); | 1316 ASSERT(blobIndex >= 0); |
1317 m_writer.writeFileIndex(blobIndex); | 1317 m_writer.writeFileIndex(blobIndex); |
1318 } else { | 1318 } else { |
1319 m_writer.writeFile(*file); | 1319 m_writer.writeFile(*file); |
1320 } | 1320 } |
1321 return 0; | 1321 return 0; |
1322 } | 1322 } |
1323 | 1323 |
1324 StateBase* writeFileList(v8::Handle<v8::Value> value, StateBase* next) | 1324 StateBase* writeFileList(v8::Handle<v8::Value> value, StateBase* next) |
1325 { | 1325 { |
1326 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1326 FileList* fileList = V8FileList::toImpl(value.As<v8::Object>()); |
1327 if (!fileList) | 1327 if (!fileList) |
1328 return 0; | 1328 return 0; |
1329 unsigned length = fileList->length(); | 1329 unsigned length = fileList->length(); |
1330 Vector<int> blobIndices; | 1330 Vector<int> blobIndices; |
1331 for (unsigned i = 0; i < length; ++i) { | 1331 for (unsigned i = 0; i < length; ++i) { |
1332 int blobIndex = -1; | 1332 int blobIndex = -1; |
1333 const File* file = fileList->item(i); | 1333 const File* file = fileList->item(i); |
1334 if (file->hasBeenClosed()) | 1334 if (file->hasBeenClosed()) |
1335 return handleError(DataCloneError, "A File object has been close
d, and could therefore not be cloned.", next); | 1335 return handleError(DataCloneError, "A File object has been close
d, and could therefore not be cloned.", next); |
1336 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); | 1336 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); |
1337 if (appendFileInfo(file, &blobIndex)) { | 1337 if (appendFileInfo(file, &blobIndex)) { |
1338 ASSERT(!i || blobIndex > 0); | 1338 ASSERT(!i || blobIndex > 0); |
1339 ASSERT(blobIndex >= 0); | 1339 ASSERT(blobIndex >= 0); |
1340 blobIndices.append(blobIndex); | 1340 blobIndices.append(blobIndex); |
1341 } | 1341 } |
1342 } | 1342 } |
1343 if (!blobIndices.isEmpty()) | 1343 if (!blobIndices.isEmpty()) |
1344 m_writer.writeFileListIndex(blobIndices); | 1344 m_writer.writeFileListIndex(blobIndices); |
1345 else | 1345 else |
1346 m_writer.writeFileList(*fileList); | 1346 m_writer.writeFileList(*fileList); |
1347 return 0; | 1347 return 0; |
1348 } | 1348 } |
1349 | 1349 |
1350 bool writeCryptoKey(v8::Handle<v8::Value> value) | 1350 bool writeCryptoKey(v8::Handle<v8::Value> value) |
1351 { | 1351 { |
1352 CryptoKey* key = V8CryptoKey::toNative(value.As<v8::Object>()); | 1352 CryptoKey* key = V8CryptoKey::toImpl(value.As<v8::Object>()); |
1353 if (!key) | 1353 if (!key) |
1354 return false; | 1354 return false; |
1355 return m_writer.writeCryptoKey(key->key()); | 1355 return m_writer.writeCryptoKey(key->key()); |
1356 } | 1356 } |
1357 | 1357 |
1358 void writeImageData(v8::Handle<v8::Value> value) | 1358 void writeImageData(v8::Handle<v8::Value> value) |
1359 { | 1359 { |
1360 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1360 ImageData* imageData = V8ImageData::toImpl(value.As<v8::Object>()); |
1361 if (!imageData) | 1361 if (!imageData) |
1362 return; | 1362 return; |
1363 Uint8ClampedArray* pixelArray = imageData->data(); | 1363 Uint8ClampedArray* pixelArray = imageData->data(); |
1364 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); | 1364 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); |
1365 } | 1365 } |
1366 | 1366 |
1367 void writeRegExp(v8::Handle<v8::Value> value) | 1367 void writeRegExp(v8::Handle<v8::Value> value) |
1368 { | 1368 { |
1369 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>(); | 1369 v8::Handle<v8::RegExp> regExp = value.As<v8::RegExp>(); |
1370 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); | 1370 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); |
1371 } | 1371 } |
1372 | 1372 |
1373 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB
ase* next) | 1373 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateB
ase* next) |
1374 { | 1374 { |
1375 ASSERT(!object.IsEmpty()); | 1375 ASSERT(!object.IsEmpty()); |
1376 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(object); | 1376 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object); |
1377 if (!arrayBufferView) | 1377 if (!arrayBufferView) |
1378 return 0; | 1378 return 0; |
1379 if (!arrayBufferView->buffer()) | 1379 if (!arrayBufferView->buffer()) |
1380 return handleError(DataCloneError, "An ArrayBuffer could not be clon
ed.", next); | 1380 return handleError(DataCloneError, "An ArrayBuffer could not be clon
ed.", next); |
1381 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(),
m_scriptState->context()->Global(), isolate()); | 1381 v8::Handle<v8::Value> underlyingBuffer = toV8(arrayBufferView->buffer(),
m_scriptState->context()->Global(), isolate()); |
1382 if (underlyingBuffer.IsEmpty()) | 1382 if (underlyingBuffer.IsEmpty()) |
1383 return handleError(DataCloneError, "An ArrayBuffer could not be clon
ed.", next); | 1383 return handleError(DataCloneError, "An ArrayBuffer could not be clon
ed.", next); |
1384 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); | 1384 StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next); |
1385 if (stateOut) | 1385 if (stateOut) |
1386 return stateOut; | 1386 return stateOut; |
1387 m_writer.writeArrayBufferView(*arrayBufferView); | 1387 m_writer.writeArrayBufferView(*arrayBufferView); |
1388 // This should be safe: we serialize something that we know to be a wrap
per (see | 1388 // This should be safe: we serialize something that we know to be a wrap
per (see |
1389 // the toV8 call above), so the call to doSerializeArrayBuffer should ne
ither | 1389 // the toV8 call above), so the call to doSerializeArrayBuffer should ne
ither |
1390 // cause the system stack to overflow nor should it have potential to re
ach | 1390 // cause the system stack to overflow nor should it have potential to re
ach |
1391 // this ArrayBufferView again. | 1391 // this ArrayBufferView again. |
1392 // | 1392 // |
1393 // We do need to grey the underlying buffer before we grey its view, how
ever; | 1393 // We do need to grey the underlying buffer before we grey its view, how
ever; |
1394 // ArrayBuffers may be shared, so they need to be given reference IDs, a
nd an | 1394 // ArrayBuffers may be shared, so they need to be given reference IDs, a
nd an |
1395 // ArrayBufferView cannot be constructed without a corresponding ArrayBu
ffer | 1395 // ArrayBufferView cannot be constructed without a corresponding ArrayBu
ffer |
1396 // (or without an additional tag that would allow us to do two-stage con
struction | 1396 // (or without an additional tag that would allow us to do two-stage con
struction |
1397 // like we do for Objects and Arrays). | 1397 // like we do for Objects and Arrays). |
1398 greyObject(object); | 1398 greyObject(object); |
1399 return 0; | 1399 return 0; |
1400 } | 1400 } |
1401 | 1401 |
1402 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next) | 1402 StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next) |
1403 { | 1403 { |
1404 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(value.As<v8::Object>(
)); | 1404 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>())
; |
1405 if (!arrayBuffer) | 1405 if (!arrayBuffer) |
1406 return 0; | 1406 return 0; |
1407 if (arrayBuffer->isNeutered()) | 1407 if (arrayBuffer->isNeutered()) |
1408 return handleError(DataCloneError, "An ArrayBuffer is neutered and c
ould not be cloned.", next); | 1408 return handleError(DataCloneError, "An ArrayBuffer is neutered and c
ould not be cloned.", next); |
1409 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>())); | 1409 ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>())); |
1410 m_writer.writeArrayBuffer(*arrayBuffer); | 1410 m_writer.writeArrayBuffer(*arrayBuffer); |
1411 return 0; | 1411 return 0; |
1412 } | 1412 } |
1413 | 1413 |
1414 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t
index, StateBase* next) | 1414 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t
index, StateBase* next) |
1415 { | 1415 { |
1416 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(value.As<v8::Object>(
)); | 1416 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>())
; |
1417 if (!arrayBuffer) | 1417 if (!arrayBuffer) |
1418 return 0; | 1418 return 0; |
1419 if (arrayBuffer->isNeutered()) | 1419 if (arrayBuffer->isNeutered()) |
1420 return handleError(DataCloneError, "An ArrayBuffer is neutered and c
ould not be cloned.", next); | 1420 return handleError(DataCloneError, "An ArrayBuffer is neutered and c
ould not be cloned.", next); |
1421 m_writer.writeTransferredArrayBuffer(index); | 1421 m_writer.writeTransferredArrayBuffer(index); |
1422 return 0; | 1422 return 0; |
1423 } | 1423 } |
1424 | 1424 |
1425 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount) | 1425 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount) |
1426 { | 1426 { |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 if (!readArrayBufferViewSubTag(&subTag)) | 2059 if (!readArrayBufferViewSubTag(&subTag)) |
2060 return false; | 2060 return false; |
2061 if (!doReadUint32(&byteOffset)) | 2061 if (!doReadUint32(&byteOffset)) |
2062 return false; | 2062 return false; |
2063 if (!doReadUint32(&byteLength)) | 2063 if (!doReadUint32(&byteLength)) |
2064 return false; | 2064 return false; |
2065 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) | 2065 if (!creator.consumeTopOfStack(&arrayBufferV8Value)) |
2066 return false; | 2066 return false; |
2067 if (arrayBufferV8Value.IsEmpty()) | 2067 if (arrayBufferV8Value.IsEmpty()) |
2068 return false; | 2068 return false; |
2069 arrayBuffer = V8ArrayBuffer::toNative(arrayBufferV8Value.As<v8::Object>(
)); | 2069 arrayBuffer = V8ArrayBuffer::toImpl(arrayBufferV8Value.As<v8::Object>())
; |
2070 if (!arrayBuffer) | 2070 if (!arrayBuffer) |
2071 return false; | 2071 return false; |
2072 | 2072 |
2073 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa
l(); | 2073 v8::Handle<v8::Object> creationContext = m_scriptState->context()->Globa
l(); |
2074 switch (subTag) { | 2074 switch (subTag) { |
2075 case ByteArrayTag: | 2075 case ByteArrayTag: |
2076 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b
yteLength), creationContext, isolate()); | 2076 *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, b
yteLength), creationContext, isolate()); |
2077 break; | 2077 break; |
2078 case UnsignedByteArrayTag: | 2078 case UnsignedByteArrayTag: |
2079 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset,
byteLength), creationContext, isolate()); | 2079 *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset,
byteLength), creationContext, isolate()); |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 // Validate the passed array of transferrables. | 3020 // Validate the passed array of transferrables. |
3021 for (unsigned i = 0; i < length; ++i) { | 3021 for (unsigned i = 0; i < length; ++i) { |
3022 v8::Local<v8::Value> transferrable = transferrables->Get(i); | 3022 v8::Local<v8::Value> transferrable = transferrables->Get(i); |
3023 // Validation of non-null objects, per HTML5 spec 10.3.3. | 3023 // Validation of non-null objects, per HTML5 spec 10.3.3. |
3024 if (isUndefinedOrNull(transferrable)) { | 3024 if (isUndefinedOrNull(transferrable)) { |
3025 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ?
"'undefined'" : "'null'") + " value."); | 3025 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " is an untransferable " + (transferrable->IsUndefined() ?
"'undefined'" : "'null'") + " value."); |
3026 return false; | 3026 return false; |
3027 } | 3027 } |
3028 // Validation of Objects implementing an interface, per WebIDL spec 4.1.
15. | 3028 // Validation of Objects implementing an interface, per WebIDL spec 4.1.
15. |
3029 if (V8MessagePort::hasInstance(transferrable, isolate)) { | 3029 if (V8MessagePort::hasInstance(transferrable, isolate)) { |
3030 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toNative(v8::H
andle<v8::Object>::Cast(transferrable)); | 3030 RefPtrWillBeRawPtr<MessagePort> port = V8MessagePort::toImpl(v8::Han
dle<v8::Object>::Cast(transferrable)); |
3031 // Check for duplicate MessagePorts. | 3031 // Check for duplicate MessagePorts. |
3032 if (ports.contains(port)) { | 3032 if (ports.contains(port)) { |
3033 exceptionState.throwDOMException(DataCloneError, "Message port a
t index " + String::number(i) + " is a duplicate of an earlier port."); | 3033 exceptionState.throwDOMException(DataCloneError, "Message port a
t index " + String::number(i) + " is a duplicate of an earlier port."); |
3034 return false; | 3034 return false; |
3035 } | 3035 } |
3036 ports.append(port.release()); | 3036 ports.append(port.release()); |
3037 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { | 3037 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { |
3038 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(v8::Handle
<v8::Object>::Cast(transferrable)); | 3038 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v
8::Object>::Cast(transferrable)); |
3039 if (arrayBuffers.contains(arrayBuffer)) { | 3039 if (arrayBuffers.contains(arrayBuffer)) { |
3040 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); | 3040 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); |
3041 return false; | 3041 return false; |
3042 } | 3042 } |
3043 arrayBuffers.append(arrayBuffer.release()); | 3043 arrayBuffers.append(arrayBuffer.release()); |
3044 } else { | 3044 } else { |
3045 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " does not have a transferable type."); | 3045 exceptionState.throwDOMException(DataCloneError, "Value at index " +
String::number(i) + " does not have a transferable type."); |
3046 return false; | 3046 return false; |
3047 } | 3047 } |
3048 } | 3048 } |
(...skipping 13 matching lines...) Expand all Loading... |
3062 // If the allocated memory was not registered before, then this class is lik
ely | 3062 // If the allocated memory was not registered before, then this class is lik
ely |
3063 // used in a context other then Worker's onmessage environment and the prese
nce of | 3063 // used in a context other then Worker's onmessage environment and the prese
nce of |
3064 // current v8 context is not guaranteed. Avoid calling v8 then. | 3064 // current v8 context is not guaranteed. Avoid calling v8 then. |
3065 if (m_externallyAllocatedMemory) { | 3065 if (m_externallyAllocatedMemory) { |
3066 ASSERT(v8::Isolate::GetCurrent()); | 3066 ASSERT(v8::Isolate::GetCurrent()); |
3067 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 3067 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
3068 } | 3068 } |
3069 } | 3069 } |
3070 | 3070 |
3071 } // namespace blink | 3071 } // namespace blink |
OLD | NEW |