| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 CounterMap* Shell::counter_map_; | 110 CounterMap* Shell::counter_map_; |
| 111 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 111 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; |
| 112 CounterCollection Shell::local_counters_; | 112 CounterCollection Shell::local_counters_; |
| 113 CounterCollection* Shell::counters_ = &local_counters_; | 113 CounterCollection* Shell::counters_ = &local_counters_; |
| 114 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); | 114 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); |
| 115 Persistent<Context> Shell::utility_context_; | 115 Persistent<Context> Shell::utility_context_; |
| 116 #endif // V8_SHARED | 116 #endif // V8_SHARED |
| 117 | 117 |
| 118 LineEditor* Shell::console = NULL; | 118 LineEditor* Shell::console = NULL; |
| 119 Persistent<Context> Shell::evaluation_context_; | 119 Persistent<Context> Shell::evaluation_context_; |
| 120 Persistent<FunctionTemplate> Shell::array_buffer_template_; |
| 120 ShellOptions Shell::options; | 121 ShellOptions Shell::options; |
| 121 const char* Shell::kPrompt = "d8> "; | 122 const char* Shell::kPrompt = "d8> "; |
| 122 | 123 |
| 123 | 124 |
| 124 const int MB = 1024 * 1024; | 125 const int MB = 1024 * 1024; |
| 125 | 126 |
| 126 | 127 |
| 127 #ifndef V8_SHARED | 128 #ifndef V8_SHARED |
| 128 bool CounterMap::Match(void* key1, void* key2) { | 129 bool CounterMap::Match(void* key1, void* key2) { |
| 129 const char* name1 = reinterpret_cast<const char*>(key1); | 130 const char* name1 = reinterpret_cast<const char*>(key1); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (source.IsEmpty()) { | 278 if (source.IsEmpty()) { |
| 278 return ThrowException(String::New("Error loading file")); | 279 return ThrowException(String::New("Error loading file")); |
| 279 } | 280 } |
| 280 if (!ExecuteString(source, String::New(*file), false, true)) { | 281 if (!ExecuteString(source, String::New(*file), false, true)) { |
| 281 return ThrowException(String::New("Error executing file")); | 282 return ThrowException(String::New("Error executing file")); |
| 282 } | 283 } |
| 283 } | 284 } |
| 284 return Undefined(); | 285 return Undefined(); |
| 285 } | 286 } |
| 286 | 287 |
| 287 static size_t convertToUint(Local<Value> value_in, TryCatch* try_catch) { | 288 |
| 288 if (value_in->IsUint32()) { | 289 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) { |
| 289 return value_in->Uint32Value(); | 290 if (value_in->IsInt32()) { |
| 291 return value_in->Int32Value(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 Local<Value> number = value_in->ToNumber(); | 294 Local<Value> number = value_in->ToNumber(); |
| 293 if (try_catch->HasCaught()) return 0; | 295 if (try_catch->HasCaught()) return 0; |
| 294 | 296 |
| 295 ASSERT(number->IsNumber()); | 297 ASSERT(number->IsNumber()); |
| 296 Local<Int32> int32 = number->ToInt32(); | 298 Local<Int32> int32 = number->ToInt32(); |
| 297 if (try_catch->HasCaught() || int32.IsEmpty()) return 0; | 299 if (try_catch->HasCaught() || int32.IsEmpty()) return 0; |
| 298 | 300 |
| 299 int32_t raw_value = int32->Int32Value(); | 301 int32_t value = int32->Int32Value(); |
| 302 if (try_catch->HasCaught()) return 0; |
| 303 |
| 304 return value; |
| 305 } |
| 306 |
| 307 |
| 308 static size_t convertToUint(Local<Value> value_in, TryCatch* try_catch) { |
| 309 if (value_in->IsUint32()) { |
| 310 return value_in->Uint32Value(); |
| 311 } |
| 312 |
| 313 int32_t raw_value = convertToInt(value_in, try_catch); |
| 300 if (try_catch->HasCaught()) return 0; | 314 if (try_catch->HasCaught()) return 0; |
| 301 | 315 |
| 302 if (raw_value < 0) { | 316 if (raw_value < 0) { |
| 303 ThrowException(String::New("Array length must not be negative.")); | 317 ThrowException(String::New("Array length must not be negative.")); |
| 304 return 0; | 318 return 0; |
| 305 } | 319 } |
| 306 | 320 |
| 307 static const int kMaxLength = 0x3fffffff; | 321 static const int kMaxLength = 0x3fffffff; |
| 308 #ifndef V8_SHARED | 322 #ifndef V8_SHARED |
| 309 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); | 323 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); |
| 310 #endif // V8_SHARED | 324 #endif // V8_SHARED |
| 311 if (raw_value > static_cast<int32_t>(kMaxLength)) { | 325 if (raw_value > static_cast<int32_t>(kMaxLength)) { |
| 312 ThrowException( | 326 ThrowException( |
| 313 String::New("Array length exceeds maximum length.")); | 327 String::New("Array length exceeds maximum length.")); |
| 314 } | 328 } |
| 315 return static_cast<size_t>(raw_value); | 329 return static_cast<size_t>(raw_value); |
| 316 } | 330 } |
| 317 | 331 |
| 318 | 332 |
| 319 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; | 333 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; |
| 334 const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; |
| 320 | 335 |
| 321 | 336 |
| 322 Handle<Value> Shell::CreateExternalArrayBuffer(int32_t length) { | 337 Handle<Value> Shell::CreateExternalArrayBuffer(Handle<Object> buffer, |
| 338 int32_t length) { |
| 323 static const int32_t kMaxSize = 0x7fffffff; | 339 static const int32_t kMaxSize = 0x7fffffff; |
| 324 // Make sure the total size fits into a (signed) int. | 340 // Make sure the total size fits into a (signed) int. |
| 325 if (length < 0 || length > kMaxSize) { | 341 if (length < 0 || length > kMaxSize) { |
| 326 return ThrowException(String::New("ArrayBuffer exceeds maximum size (2G)")); | 342 return ThrowException(String::New("ArrayBuffer exceeds maximum size (2G)")); |
| 327 } | 343 } |
| 328 uint8_t* data = new uint8_t[length]; | 344 uint8_t* data = new uint8_t[length]; |
| 329 if (data == NULL) { | 345 if (data == NULL) { |
| 330 return ThrowException(String::New("Memory allocation failed.")); | 346 return ThrowException(String::New("Memory allocation failed.")); |
| 331 } | 347 } |
| 332 memset(data, 0, length); | 348 memset(data, 0, length); |
| 333 | 349 |
| 334 Handle<Object> buffer = Object::New(); | |
| 335 buffer->SetHiddenValue(String::New(kArrayBufferMarkerPropName), True()); | 350 buffer->SetHiddenValue(String::New(kArrayBufferMarkerPropName), True()); |
| 336 Persistent<Object> persistent_array = Persistent<Object>::New(buffer); | 351 Persistent<Object> persistent_array = Persistent<Object>::New(buffer); |
| 337 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 352 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); |
| 338 persistent_array.MarkIndependent(); | 353 persistent_array.MarkIndependent(); |
| 339 V8::AdjustAmountOfExternalAllocatedMemory(length); | 354 V8::AdjustAmountOfExternalAllocatedMemory(length); |
| 340 | 355 |
| 341 buffer->SetIndexedPropertiesToExternalArrayData( | 356 buffer->SetIndexedPropertiesToExternalArrayData( |
| 342 data, v8::kExternalByteArray, length); | 357 data, v8::kExternalByteArray, length); |
| 343 buffer->Set(String::New("byteLength"), Int32::New(length), ReadOnly); | 358 buffer->Set(String::New("byteLength"), Int32::New(length), ReadOnly); |
| 344 | 359 |
| 345 return buffer; | 360 return buffer; |
| 346 } | 361 } |
| 347 | 362 |
| 348 | 363 |
| 349 Handle<Value> Shell::CreateExternalArrayBuffer(const Arguments& args) { | 364 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { |
| 365 if (!args.IsConstructCall()) { |
| 366 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; |
| 367 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i]; |
| 368 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args); |
| 369 delete[] rec_args; |
| 370 return result; |
| 371 } |
| 372 |
| 350 if (args.Length() == 0) { | 373 if (args.Length() == 0) { |
| 351 return ThrowException( | 374 return ThrowException( |
| 352 String::New("ArrayBuffer constructor must have one parameter.")); | 375 String::New("ArrayBuffer constructor must have one parameter.")); |
| 353 } | 376 } |
| 354 TryCatch try_catch; | 377 TryCatch try_catch; |
| 355 int32_t length = convertToUint(args[0], &try_catch); | 378 int32_t length = convertToUint(args[0], &try_catch); |
| 356 if (try_catch.HasCaught()) return try_catch.Exception(); | 379 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 357 | 380 |
| 358 return CreateExternalArrayBuffer(length); | 381 return CreateExternalArrayBuffer(args.This(), length); |
| 382 } |
| 383 |
| 384 |
| 385 Handle<Object> Shell::CreateExternalArray(Handle<Object> array, |
| 386 Handle<Object> buffer, |
| 387 ExternalArrayType type, |
| 388 int32_t length, |
| 389 int32_t byteLength, |
| 390 int32_t byteOffset, |
| 391 int32_t element_size) { |
| 392 ASSERT(element_size == 1 || element_size == 2 || |
| 393 element_size == 4 || element_size == 8); |
| 394 ASSERT(byteLength == length * element_size); |
| 395 |
| 396 void* data = buffer->GetIndexedPropertiesExternalArrayData(); |
| 397 ASSERT(data != NULL); |
| 398 |
| 399 array->SetIndexedPropertiesToExternalArrayData( |
| 400 static_cast<uint8_t*>(data) + byteOffset, type, length); |
| 401 array->SetHiddenValue(String::New(kArrayMarkerPropName), Int32::New(type)); |
| 402 array->Set(String::New("byteLength"), Int32::New(byteLength), ReadOnly); |
| 403 array->Set(String::New("byteOffset"), Int32::New(byteOffset), ReadOnly); |
| 404 array->Set(String::New("length"), Int32::New(length), ReadOnly); |
| 405 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); |
| 406 array->Set(String::New("buffer"), buffer, ReadOnly); |
| 407 |
| 408 return array; |
| 359 } | 409 } |
| 360 | 410 |
| 361 | 411 |
| 362 Handle<Value> Shell::CreateExternalArray(const Arguments& args, | 412 Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
| 363 ExternalArrayType type, | 413 ExternalArrayType type, |
| 364 int32_t element_size) { | 414 int32_t element_size) { |
| 415 if (!args.IsConstructCall()) { |
| 416 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; |
| 417 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i]; |
| 418 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args); |
| 419 delete[] rec_args; |
| 420 return result; |
| 421 } |
| 422 |
| 365 TryCatch try_catch; | 423 TryCatch try_catch; |
| 366 ASSERT(element_size == 1 || element_size == 2 || | 424 ASSERT(element_size == 1 || element_size == 2 || |
| 367 element_size == 4 || element_size == 8); | 425 element_size == 4 || element_size == 8); |
| 368 | 426 |
| 369 // Currently, only the following constructors are supported: | 427 // All of the following constructors are supported: |
| 370 // TypedArray(unsigned long length) | 428 // TypedArray(unsigned long length) |
| 429 // TypedArray(type[] array) |
| 430 // TypedArray(TypedArray array) |
| 371 // TypedArray(ArrayBuffer buffer, | 431 // TypedArray(ArrayBuffer buffer, |
| 372 // optional unsigned long byteOffset, | 432 // optional unsigned long byteOffset, |
| 373 // optional unsigned long length) | 433 // optional unsigned long length) |
| 374 Handle<Object> buffer; | 434 Handle<Object> buffer; |
| 375 int32_t length; | 435 int32_t length; |
| 376 int32_t byteLength; | 436 int32_t byteLength; |
| 377 int32_t byteOffset; | 437 int32_t byteOffset; |
| 438 bool init_from_array = false; |
| 378 if (args.Length() == 0) { | 439 if (args.Length() == 0) { |
| 379 return ThrowException( | 440 return ThrowException( |
| 380 String::New("Array constructor must have at least one parameter.")); | 441 String::New("Array constructor must have at least one parameter.")); |
| 381 } | 442 } |
| 382 if (args[0]->IsObject() && | 443 if (args[0]->IsObject() && |
| 383 !args[0]->ToObject()->GetHiddenValue( | 444 !args[0]->ToObject()->GetHiddenValue( |
| 384 String::New(kArrayBufferMarkerPropName)).IsEmpty()) { | 445 String::New(kArrayBufferMarkerPropName)).IsEmpty()) { |
| 446 // Construct from ArrayBuffer. |
| 385 buffer = args[0]->ToObject(); | 447 buffer = args[0]->ToObject(); |
| 386 int32_t bufferLength = | 448 int32_t bufferLength = |
| 387 convertToUint(buffer->Get(String::New("byteLength")), &try_catch); | 449 convertToUint(buffer->Get(String::New("byteLength")), &try_catch); |
| 388 if (try_catch.HasCaught()) return try_catch.Exception(); | 450 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 389 | 451 |
| 390 if (args.Length() < 2 || args[1]->IsUndefined()) { | 452 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 391 byteOffset = 0; | 453 byteOffset = 0; |
| 392 } else { | 454 } else { |
| 393 byteOffset = convertToUint(args[1], &try_catch); | 455 byteOffset = convertToUint(args[1], &try_catch); |
| 394 if (try_catch.HasCaught()) return try_catch.Exception(); | 456 if (try_catch.HasCaught()) return try_catch.Exception(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 410 } | 472 } |
| 411 } else { | 473 } else { |
| 412 length = convertToUint(args[2], &try_catch); | 474 length = convertToUint(args[2], &try_catch); |
| 413 if (try_catch.HasCaught()) return try_catch.Exception(); | 475 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 414 byteLength = length * element_size; | 476 byteLength = length * element_size; |
| 415 if (byteOffset + byteLength > bufferLength) { | 477 if (byteOffset + byteLength > bufferLength) { |
| 416 return ThrowException(String::New("length out of bounds")); | 478 return ThrowException(String::New("length out of bounds")); |
| 417 } | 479 } |
| 418 } | 480 } |
| 419 } else { | 481 } else { |
| 420 length = convertToUint(args[0], &try_catch); | 482 if (args[0]->IsObject() && |
| 483 args[0]->ToObject()->Has(String::New("length"))) { |
| 484 // Construct from array. |
| 485 length = convertToUint( |
| 486 args[0]->ToObject()->Get(String::New("length")), &try_catch); |
| 487 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 488 init_from_array = true; |
| 489 } else { |
| 490 // Construct from size. |
| 491 length = convertToUint(args[0], &try_catch); |
| 492 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 493 } |
| 421 byteLength = length * element_size; | 494 byteLength = length * element_size; |
| 422 byteOffset = 0; | 495 byteOffset = 0; |
| 423 Handle<Value> result = CreateExternalArrayBuffer(byteLength); | 496 |
| 424 if (!result->IsObject()) return result; | 497 Handle<Value> array_buffer = array_buffer_template_->GetFunction(); |
| 498 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); |
| 499 Handle<Value> buffer_args[] = { Uint32::New(byteLength) }; |
| 500 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( |
| 501 ARRAY_SIZE(buffer_args), buffer_args); |
| 502 if (try_catch.HasCaught()) return result; |
| 425 buffer = result->ToObject(); | 503 buffer = result->ToObject(); |
| 426 } | 504 } |
| 427 | 505 |
| 428 void* data = buffer->GetIndexedPropertiesExternalArrayData(); | 506 Handle<Object> array = CreateExternalArray( |
| 429 ASSERT(data != NULL); | 507 args.This(), buffer, type, length, byteLength, byteOffset, element_size); |
| 430 | 508 |
| 431 Handle<Object> array = Object::New(); | 509 if (init_from_array) { |
| 432 array->SetIndexedPropertiesToExternalArrayData( | 510 Handle<Object> init = args[0]->ToObject(); |
| 433 static_cast<uint8_t*>(data) + byteOffset, type, length); | 511 for (int i = 0; i < length; ++i) array->Set(i, init->Get(i)); |
| 434 array->Set(String::New("byteLength"), Int32::New(byteLength), ReadOnly); | 512 } |
| 435 array->Set(String::New("byteOffset"), Int32::New(byteOffset), ReadOnly); | |
| 436 array->Set(String::New("length"), Int32::New(length), ReadOnly); | |
| 437 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); | |
| 438 array->Set(String::New("buffer"), buffer, ReadOnly); | |
| 439 | 513 |
| 440 return array; | 514 return array; |
| 441 } | 515 } |
| 442 | 516 |
| 443 | 517 |
| 518 Handle<Value> Shell::SubArray(const Arguments& args) { |
| 519 TryCatch try_catch; |
| 520 |
| 521 if (!args.This()->IsObject()) { |
| 522 return ThrowException( |
| 523 String::New("subarray invoked on non-object receiver.")); |
| 524 } |
| 525 |
| 526 Local<Object> self = args.This(); |
| 527 Local<Value> marker = self->GetHiddenValue(String::New(kArrayMarkerPropName)); |
| 528 if (marker.IsEmpty()) { |
| 529 return ThrowException( |
| 530 String::New("subarray invoked on wrong receiver type.")); |
| 531 } |
| 532 |
| 533 Handle<Object> buffer = self->Get(String::New("buffer"))->ToObject(); |
| 534 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 535 int32_t length = |
| 536 convertToUint(self->Get(String::New("length")), &try_catch); |
| 537 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 538 int32_t byteOffset = |
| 539 convertToUint(self->Get(String::New("byteOffset")), &try_catch); |
| 540 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 541 int32_t element_size = |
| 542 convertToUint(self->Get(String::New("BYTES_PER_ELEMENT")), &try_catch); |
| 543 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 544 |
| 545 if (args.Length() == 0) { |
| 546 return ThrowException( |
| 547 String::New("subarray must have at least one parameter.")); |
| 548 } |
| 549 int32_t begin = convertToInt(args[0], &try_catch); |
| 550 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 551 if (begin < 0) begin += length; |
| 552 if (begin < 0) begin = 0; |
| 553 if (begin > length) begin = length; |
| 554 |
| 555 int32_t end; |
| 556 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 557 end = length; |
| 558 } else { |
| 559 end = convertToInt(args[1], &try_catch); |
| 560 if (try_catch.HasCaught()) return try_catch.Exception(); |
| 561 if (end < 0) end += length; |
| 562 if (end < 0) end = 0; |
| 563 if (end > length) end = length; |
| 564 if (end < begin) end = begin; |
| 565 } |
| 566 |
| 567 length = end - begin; |
| 568 byteOffset += begin * element_size; |
| 569 |
| 570 Local<Function> constructor = Local<Function>::Cast(self->GetConstructor()); |
| 571 Handle<Value> construct_args[] = { |
| 572 buffer, Uint32::New(byteOffset), Uint32::New(length) |
| 573 }; |
| 574 return constructor->NewInstance(ARRAY_SIZE(construct_args), construct_args); |
| 575 } |
| 576 |
| 577 |
| 444 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 578 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
| 445 HandleScope scope; | 579 HandleScope scope; |
| 446 int32_t length = | 580 int32_t length = |
| 447 object->ToObject()->Get(String::New("byteLength"))->Uint32Value(); | 581 object->ToObject()->Get(String::New("byteLength"))->Uint32Value(); |
| 448 V8::AdjustAmountOfExternalAllocatedMemory(-length); | 582 V8::AdjustAmountOfExternalAllocatedMemory(-length); |
| 449 delete[] static_cast<uint8_t*>(data); | 583 delete[] static_cast<uint8_t*>(data); |
| 450 object.Dispose(); | 584 object.Dispose(); |
| 451 } | 585 } |
| 452 | 586 |
| 453 | 587 |
| 454 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { | |
| 455 return CreateExternalArrayBuffer(args); | |
| 456 } | |
| 457 | |
| 458 | |
| 459 Handle<Value> Shell::Int8Array(const Arguments& args) { | 588 Handle<Value> Shell::Int8Array(const Arguments& args) { |
| 460 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); | 589 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); |
| 461 } | 590 } |
| 462 | 591 |
| 463 | 592 |
| 464 Handle<Value> Shell::Uint8Array(const Arguments& args) { | 593 Handle<Value> Shell::Uint8Array(const Arguments& args) { |
| 465 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t)); | 594 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t)); |
| 466 } | 595 } |
| 467 | 596 |
| 468 | 597 |
| 469 Handle<Value> Shell::Int16Array(const Arguments& args) { | 598 Handle<Value> Shell::Int16Array(const Arguments& args) { |
| 470 return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t)); | 599 return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t)); |
| 471 } | 600 } |
| 472 | 601 |
| 473 | 602 |
| 474 Handle<Value> Shell::Uint16Array(const Arguments& args) { | 603 Handle<Value> Shell::Uint16Array(const Arguments& args) { |
| 475 return CreateExternalArray(args, kExternalUnsignedShortArray, | 604 return CreateExternalArray( |
| 476 sizeof(uint16_t)); | 605 args, kExternalUnsignedShortArray, sizeof(uint16_t)); |
| 477 } | 606 } |
| 478 | 607 |
| 479 | 608 |
| 480 Handle<Value> Shell::Int32Array(const Arguments& args) { | 609 Handle<Value> Shell::Int32Array(const Arguments& args) { |
| 481 return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t)); | 610 return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t)); |
| 482 } | 611 } |
| 483 | 612 |
| 484 | 613 |
| 485 Handle<Value> Shell::Uint32Array(const Arguments& args) { | 614 Handle<Value> Shell::Uint32Array(const Arguments& args) { |
| 486 return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t)); | 615 return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t)); |
| 487 } | 616 } |
| 488 | 617 |
| 489 | 618 |
| 490 Handle<Value> Shell::Float32Array(const Arguments& args) { | 619 Handle<Value> Shell::Float32Array(const Arguments& args) { |
| 491 return CreateExternalArray(args, kExternalFloatArray, | 620 return CreateExternalArray( |
| 492 sizeof(float)); // NOLINT | 621 args, kExternalFloatArray, sizeof(float)); // NOLINT |
| 493 } | 622 } |
| 494 | 623 |
| 495 | 624 |
| 496 Handle<Value> Shell::Float64Array(const Arguments& args) { | 625 Handle<Value> Shell::Float64Array(const Arguments& args) { |
| 497 return CreateExternalArray(args, kExternalDoubleArray, | 626 return CreateExternalArray( |
| 498 sizeof(double)); // NOLINT | 627 args, kExternalDoubleArray, sizeof(double)); // NOLINT |
| 499 } | 628 } |
| 500 | 629 |
| 501 | 630 |
| 502 Handle<Value> Shell::PixelArray(const Arguments& args) { | 631 Handle<Value> Shell::Uint8ClampedArray(const Arguments& args) { |
| 503 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t)); | 632 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t)); |
| 504 } | 633 } |
| 505 | 634 |
| 506 | 635 |
| 507 Handle<Value> Shell::Yield(const Arguments& args) { | 636 Handle<Value> Shell::Yield(const Arguments& args) { |
| 508 v8::Unlocker unlocker; | 637 v8::Unlocker unlocker; |
| 509 return Undefined(); | 638 return Undefined(); |
| 510 } | 639 } |
| 511 | 640 |
| 512 | 641 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 compressed_data_size, | 916 compressed_data_size, |
| 788 0, 1); | 917 0, 1); |
| 789 if (result == BZ_OK) { | 918 if (result == BZ_OK) { |
| 790 *raw_data_size = decompressed_size; | 919 *raw_data_size = decompressed_size; |
| 791 } | 920 } |
| 792 return result; | 921 return result; |
| 793 } | 922 } |
| 794 }; | 923 }; |
| 795 #endif | 924 #endif |
| 796 | 925 |
| 926 |
| 927 Handle<FunctionTemplate> Shell::CreateArrayTemplate(InvocationCallback fun) { |
| 928 Handle<FunctionTemplate> array_template = FunctionTemplate::New(fun); |
| 929 Local<Template> proto_template = array_template->PrototypeTemplate(); |
| 930 proto_template->Set(String::New("subarray"), FunctionTemplate::New(SubArray)); |
| 931 return array_template; |
| 932 } |
| 933 |
| 934 |
| 797 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { | 935 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
| 798 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 936 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 799 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 937 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
| 800 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 938 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
| 801 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 939 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
| 802 global_template->Set(String::New("readbuffer"), | 940 global_template->Set(String::New("readbuffer"), |
| 803 FunctionTemplate::New(ReadBuffer)); | 941 FunctionTemplate::New(ReadBuffer)); |
| 804 global_template->Set(String::New("readline"), | 942 global_template->Set(String::New("readline"), |
| 805 FunctionTemplate::New(ReadLine)); | 943 FunctionTemplate::New(ReadLine)); |
| 806 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 944 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
| 807 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 945 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
| 808 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 946 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
| 809 global_template->Set(String::New("enableProfiler"), | 947 global_template->Set(String::New("enableProfiler"), |
| 810 FunctionTemplate::New(EnableProfiler)); | 948 FunctionTemplate::New(EnableProfiler)); |
| 811 global_template->Set(String::New("disableProfiler"), | 949 global_template->Set(String::New("disableProfiler"), |
| 812 FunctionTemplate::New(DisableProfiler)); | 950 FunctionTemplate::New(DisableProfiler)); |
| 813 | 951 |
| 814 // Bind the handlers for external arrays. | 952 // Bind the handlers for external arrays. |
| 953 PropertyAttribute attr = |
| 954 static_cast<PropertyAttribute>(ReadOnly | DontDelete); |
| 955 array_buffer_template_ = |
| 956 Persistent<FunctionTemplate>::New(CreateArrayTemplate(ArrayBuffer)); |
| 815 global_template->Set(String::New("ArrayBuffer"), | 957 global_template->Set(String::New("ArrayBuffer"), |
| 816 FunctionTemplate::New(ArrayBuffer)); | 958 array_buffer_template_, attr); |
| 817 global_template->Set(String::New("Int8Array"), | 959 global_template->Set(String::New("Int8Array"), |
| 818 FunctionTemplate::New(Int8Array)); | 960 CreateArrayTemplate(Int8Array), attr); |
| 819 global_template->Set(String::New("Uint8Array"), | 961 global_template->Set(String::New("Uint8Array"), |
| 820 FunctionTemplate::New(Uint8Array)); | 962 CreateArrayTemplate(Uint8Array), attr); |
| 821 global_template->Set(String::New("Int16Array"), | 963 global_template->Set(String::New("Int16Array"), |
| 822 FunctionTemplate::New(Int16Array)); | 964 CreateArrayTemplate(Int16Array), attr); |
| 823 global_template->Set(String::New("Uint16Array"), | 965 global_template->Set(String::New("Uint16Array"), |
| 824 FunctionTemplate::New(Uint16Array)); | 966 CreateArrayTemplate(Uint16Array), attr); |
| 825 global_template->Set(String::New("Int32Array"), | 967 global_template->Set(String::New("Int32Array"), |
| 826 FunctionTemplate::New(Int32Array)); | 968 CreateArrayTemplate(Int32Array), attr); |
| 827 global_template->Set(String::New("Uint32Array"), | 969 global_template->Set(String::New("Uint32Array"), |
| 828 FunctionTemplate::New(Uint32Array)); | 970 CreateArrayTemplate(Uint32Array), attr); |
| 829 global_template->Set(String::New("Float32Array"), | 971 global_template->Set(String::New("Float32Array"), |
| 830 FunctionTemplate::New(Float32Array)); | 972 CreateArrayTemplate(Float32Array), attr); |
| 831 global_template->Set(String::New("Float64Array"), | 973 global_template->Set(String::New("Float64Array"), |
| 832 FunctionTemplate::New(Float64Array)); | 974 CreateArrayTemplate(Float64Array), attr); |
| 833 global_template->Set(String::New("PixelArray"), | 975 global_template->Set(String::New("Uint8ClampedArray"), |
| 834 FunctionTemplate::New(PixelArray)); | 976 CreateArrayTemplate(Uint8ClampedArray), attr); |
| 835 | 977 |
| 836 #ifdef LIVE_OBJECT_LIST | 978 #ifdef LIVE_OBJECT_LIST |
| 837 global_template->Set(String::New("lol_is_enabled"), True()); | 979 global_template->Set(String::New("lol_is_enabled"), True()); |
| 838 #else | 980 #else |
| 839 global_template->Set(String::New("lol_is_enabled"), False()); | 981 global_template->Set(String::New("lol_is_enabled"), False()); |
| 840 #endif | 982 #endif |
| 841 | 983 |
| 842 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) | 984 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) |
| 843 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 985 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 844 AddOSMethods(os_templ); | 986 AddOSMethods(os_templ); |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 } | 1684 } |
| 1543 | 1685 |
| 1544 } // namespace v8 | 1686 } // namespace v8 |
| 1545 | 1687 |
| 1546 | 1688 |
| 1547 #ifndef GOOGLE3 | 1689 #ifndef GOOGLE3 |
| 1548 int main(int argc, char* argv[]) { | 1690 int main(int argc, char* argv[]) { |
| 1549 return v8::Shell::Main(argc, argv); | 1691 return v8::Shell::Main(argc, argv); |
| 1550 } | 1692 } |
| 1551 #endif | 1693 #endif |
| OLD | NEW |