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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 array->Set(String::New("length"), Int32::New(length), ReadOnly); | 436 array->Set(String::New("length"), Int32::New(length), ReadOnly); |
437 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); | 437 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); |
438 array->Set(String::New("buffer"), buffer, ReadOnly); | 438 array->Set(String::New("buffer"), buffer, ReadOnly); |
439 | 439 |
440 return array; | 440 return array; |
441 } | 441 } |
442 | 442 |
443 | 443 |
444 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 444 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
445 HandleScope scope; | 445 HandleScope scope; |
446 int32_t length = | 446 Local<Value> length = object->ToObject()->Get(String::New("byteLength")); |
447 object->ToObject()->Get(String::New("byteLength"))->Uint32Value(); | 447 V8::AdjustAmountOfExternalAllocatedMemory(-length->Uint32Value()); |
448 V8::AdjustAmountOfExternalAllocatedMemory(-length); | |
449 delete[] static_cast<uint8_t*>(data); | 448 delete[] static_cast<uint8_t*>(data); |
450 object.Dispose(); | 449 object.Dispose(); |
451 } | 450 } |
452 | 451 |
453 | 452 |
454 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { | 453 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { |
455 return CreateExternalArrayBuffer(args); | 454 return CreateExternalArrayBuffer(args); |
456 } | 455 } |
457 | 456 |
458 | 457 |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); | 1012 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
1014 i += read; | 1013 i += read; |
1015 } | 1014 } |
1016 fclose(file); | 1015 fclose(file); |
1017 *size_out = size; | 1016 *size_out = size; |
1018 return chars; | 1017 return chars; |
1019 } | 1018 } |
1020 | 1019 |
1021 | 1020 |
1022 Handle<Value> Shell::ReadBuffer(const Arguments& args) { | 1021 Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
1023 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT | 1022 STATIC_ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT |
1024 String::Utf8Value filename(args[0]); | 1023 String::Utf8Value filename(args[0]); |
1025 int length; | 1024 int length; |
1026 if (*filename == NULL) { | 1025 if (*filename == NULL) { |
1027 return ThrowException(String::New("Error loading file")); | 1026 return ThrowException(String::New("Error loading file")); |
1028 } | 1027 } |
1029 | 1028 |
1030 uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length)); | 1029 uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length)); |
1031 if (data == NULL) { | 1030 if (data == NULL) { |
1032 return ThrowException(String::New("Error reading file")); | 1031 return ThrowException(String::New("Error reading file")); |
1033 } | 1032 } |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 } | 1541 } |
1543 | 1542 |
1544 } // namespace v8 | 1543 } // namespace v8 |
1545 | 1544 |
1546 | 1545 |
1547 #ifndef GOOGLE3 | 1546 #ifndef GOOGLE3 |
1548 int main(int argc, char* argv[]) { | 1547 int main(int argc, char* argv[]) { |
1549 return v8::Shell::Main(argc, argv); | 1548 return v8::Shell::Main(argc, argv); |
1550 } | 1549 } |
1551 #endif | 1550 #endif |
OLD | NEW |