OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 v8::String::New("Array constructor needs one parameter.")); | 459 v8::String::New("Array constructor needs one parameter.")); |
460 } | 460 } |
461 int length = args[0]->Int32Value(); | 461 int length = args[0]->Int32Value(); |
462 void* data = malloc(length * element_size); | 462 void* data = malloc(length * element_size); |
463 memset(data, 0, length * element_size); | 463 memset(data, 0, length * element_size); |
464 v8::Handle<v8::Object> array = v8::Object::New(); | 464 v8::Handle<v8::Object> array = v8::Object::New(); |
465 v8::Persistent<v8::Object> persistent_array = | 465 v8::Persistent<v8::Object> persistent_array = |
466 v8::Persistent<v8::Object>::New(array); | 466 v8::Persistent<v8::Object>::New(array); |
467 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 467 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); |
468 array->SetIndexedPropertiesToExternalArrayData(data, type, length); | 468 array->SetIndexedPropertiesToExternalArrayData(data, type, length); |
| 469 array->Set(v8::String::New("length"), v8::Int32::New(length), |
| 470 v8::ReadOnly); |
| 471 array->Set(v8::String::New("BYTES_PER_ELEMENT"), |
| 472 v8::Int32::New(element_size)); |
469 return array; | 473 return array; |
470 } | 474 } |
471 | 475 |
472 | 476 |
473 v8::Handle<v8::Value> Int8Array(const v8::Arguments& args) { | 477 v8::Handle<v8::Value> Int8Array(const v8::Arguments& args) { |
474 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); | 478 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); |
475 } | 479 } |
476 | 480 |
477 | 481 |
478 v8::Handle<v8::Value> Uint8Array(const v8::Arguments& args) { | 482 v8::Handle<v8::Value> Uint8Array(const v8::Arguments& args) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 printf("^"); | 625 printf("^"); |
622 } | 626 } |
623 printf("\n"); | 627 printf("\n"); |
624 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); | 628 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); |
625 if (stack_trace.length() > 0) { | 629 if (stack_trace.length() > 0) { |
626 const char* stack_trace_string = ToCString(stack_trace); | 630 const char* stack_trace_string = ToCString(stack_trace); |
627 printf("%s\n", stack_trace_string); | 631 printf("%s\n", stack_trace_string); |
628 } | 632 } |
629 } | 633 } |
630 } | 634 } |
OLD | NEW |