OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // Hold a reference to the ArrayBuffer so its buffer doesn't get collected. | 420 // Hold a reference to the ArrayBuffer so its buffer doesn't get collected. |
421 array->Set(String::New(kArrayBufferReferencePropName), args[0], ReadOnly); | 421 array->Set(String::New(kArrayBufferReferencePropName), args[0], ReadOnly); |
422 } | 422 } |
423 | 423 |
424 if (is_array_buffer_construct) { | 424 if (is_array_buffer_construct) { |
425 array->Set(String::New(kArrayBufferMarkerPropName), True(), ReadOnly); | 425 array->Set(String::New(kArrayBufferMarkerPropName), True(), ReadOnly); |
426 } | 426 } |
427 | 427 |
428 Persistent<Object> persistent_array = Persistent<Object>::New(array); | 428 Persistent<Object> persistent_array = Persistent<Object>::New(array); |
429 if (data == NULL && length != 0) { | 429 if (data == NULL && length != 0) { |
| 430 // Make sure the total size fits into a (signed) int. |
| 431 static const int kMaxSize = 0x7fffffff; |
| 432 if (length > (kMaxSize - sizeof(size_t)) / element_size) { |
| 433 return ThrowException(String::New("Array exceeds maximum size (2G)")); |
| 434 } |
430 // Prepend the size of the allocated chunk to the data itself. | 435 // Prepend the size of the allocated chunk to the data itself. |
431 int total_size = length * element_size + sizeof(size_t); | 436 int total_size = length * element_size + sizeof(size_t); |
432 data = malloc(total_size); | 437 data = malloc(total_size); |
433 if (data == NULL) { | 438 if (data == NULL) { |
434 return ThrowException(String::New("Memory allocation failed.")); | 439 return ThrowException(String::New("Memory allocation failed.")); |
435 } | 440 } |
436 *reinterpret_cast<size_t*>(data) = total_size; | 441 *reinterpret_cast<size_t*>(data) = total_size; |
437 data = reinterpret_cast<size_t*>(data) + 1; | 442 data = reinterpret_cast<size_t*>(data) + 1; |
438 memset(data, 0, length * element_size); | 443 memset(data, 0, length * element_size); |
439 V8::AdjustAmountOfExternalAllocatedMemory(total_size); | 444 V8::AdjustAmountOfExternalAllocatedMemory(total_size); |
(...skipping 13 matching lines...) Expand all Loading... |
453 | 458 |
454 | 459 |
455 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 460 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
456 HandleScope scope; | 461 HandleScope scope; |
457 Handle<String> prop_name = String::New(kArrayBufferReferencePropName); | 462 Handle<String> prop_name = String::New(kArrayBufferReferencePropName); |
458 Handle<Object> converted_object = object->ToObject(); | 463 Handle<Object> converted_object = object->ToObject(); |
459 Local<Value> prop_value = converted_object->Get(prop_name); | 464 Local<Value> prop_value = converted_object->Get(prop_name); |
460 if (data != NULL && !prop_value->IsObject()) { | 465 if (data != NULL && !prop_value->IsObject()) { |
461 data = reinterpret_cast<size_t*>(data) - 1; | 466 data = reinterpret_cast<size_t*>(data) - 1; |
462 V8::AdjustAmountOfExternalAllocatedMemory( | 467 V8::AdjustAmountOfExternalAllocatedMemory( |
463 -(*reinterpret_cast<size_t*>(data))); | 468 -static_cast<int>(*reinterpret_cast<size_t*>(data))); |
464 free(data); | 469 free(data); |
465 } | 470 } |
466 object.Dispose(); | 471 object.Dispose(); |
467 } | 472 } |
468 | 473 |
469 | 474 |
470 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { | 475 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { |
471 return CreateExternalArray(args, v8::kExternalByteArray, 0); | 476 return CreateExternalArray(args, v8::kExternalByteArray, 0); |
472 } | 477 } |
473 | 478 |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 } | 1553 } |
1549 | 1554 |
1550 } // namespace v8 | 1555 } // namespace v8 |
1551 | 1556 |
1552 | 1557 |
1553 #ifndef GOOGLE3 | 1558 #ifndef GOOGLE3 |
1554 int main(int argc, char* argv[]) { | 1559 int main(int argc, char* argv[]) { |
1555 return v8::Shell::Main(argc, argv); | 1560 return v8::Shell::Main(argc, argv); |
1556 } | 1561 } |
1557 #endif | 1562 #endif |
OLD | NEW |