| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #if !defined(_WIN32) && !defined(_WIN64) | 60 #if !defined(_WIN32) && !defined(_WIN64) |
| 61 #include <unistd.h> // NOLINT | 61 #include <unistd.h> // NOLINT |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 #ifndef ASSERT | 64 #ifndef ASSERT |
| 65 #define ASSERT(condition) assert(condition) | 65 #define ASSERT(condition) assert(condition) |
| 66 #endif | 66 #endif |
| 67 | 67 |
| 68 namespace v8 { | 68 namespace v8 { |
| 69 | 69 |
| 70 | |
| 71 static Handle<Value> Throw(const char* message) { | |
| 72 return ThrowException(String::New(message)); | |
| 73 } | |
| 74 | |
| 75 | |
| 76 // TODO(rossberg): should replace these by proper uses of HasInstance, | |
| 77 // once we figure out a good way to make the templates global. | |
| 78 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; | |
| 79 const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; | |
| 80 | |
| 81 | |
| 82 namespace Symbols { | |
| 83 #define FOR_EACH_SYMBOL(V) \ | |
| 84 V(ArrayBuffer, "ArrayBuffer") \ | |
| 85 V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \ | |
| 86 V(ArrayMarkerPropName, kArrayMarkerPropName) \ | |
| 87 V(buffer, "buffer") \ | |
| 88 V(byteLength, "byteLength") \ | |
| 89 V(byteOffset, "byteOffset") \ | |
| 90 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ | |
| 91 V(length, "length") | |
| 92 | |
| 93 #define DEFINE_SYMBOL(name, value) Persistent<String> name; | |
| 94 FOR_EACH_SYMBOL(DEFINE_SYMBOL) | |
| 95 #undef DEFINE_SYMBOL | |
| 96 | |
| 97 void Initialize() { | |
| 98 HandleScope scope; | |
| 99 #define INIT_SYMBOL(name, value) \ | |
| 100 name = Persistent<String>::New(String::NewSymbol(value)); | |
| 101 FOR_EACH_SYMBOL(INIT_SYMBOL) | |
| 102 #undef INIT_SYMBOL | |
| 103 } | |
| 104 | |
| 105 void TearDown() { | |
| 106 #define DISPOSE_SYMBOL(name, value) name.Dispose(); | |
| 107 FOR_EACH_SYMBOL(DISPOSE_SYMBOL) | |
| 108 #undef DISPOSE_SYMBOL | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 | |
| 113 LineEditor *LineEditor::first_ = NULL; | 70 LineEditor *LineEditor::first_ = NULL; |
| 114 | 71 |
| 115 | 72 |
| 116 LineEditor::LineEditor(Type type, const char* name) | 73 LineEditor::LineEditor(Type type, const char* name) |
| 117 : type_(type), | 74 : type_(type), |
| 118 name_(name), | 75 name_(name), |
| 119 next_(first_) { | 76 next_(first_) { |
| 120 first_ = this; | 77 first_ = this; |
| 121 } | 78 } |
| 122 | 79 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 225 |
| 269 Handle<Value> Shell::DisableProfiler(const Arguments& args) { | 226 Handle<Value> Shell::DisableProfiler(const Arguments& args) { |
| 270 V8::PauseProfiler(); | 227 V8::PauseProfiler(); |
| 271 return Undefined(); | 228 return Undefined(); |
| 272 } | 229 } |
| 273 | 230 |
| 274 | 231 |
| 275 Handle<Value> Shell::Read(const Arguments& args) { | 232 Handle<Value> Shell::Read(const Arguments& args) { |
| 276 String::Utf8Value file(args[0]); | 233 String::Utf8Value file(args[0]); |
| 277 if (*file == NULL) { | 234 if (*file == NULL) { |
| 278 return Throw("Error loading file"); | 235 return ThrowException(String::New("Error loading file")); |
| 279 } | 236 } |
| 280 Handle<String> source = ReadFile(*file); | 237 Handle<String> source = ReadFile(*file); |
| 281 if (source.IsEmpty()) { | 238 if (source.IsEmpty()) { |
| 282 return Throw("Error loading file"); | 239 return ThrowException(String::New("Error loading file")); |
| 283 } | 240 } |
| 284 return source; | 241 return source; |
| 285 } | 242 } |
| 286 | 243 |
| 287 | 244 |
| 288 Handle<String> Shell::ReadFromStdin() { | 245 Handle<String> Shell::ReadFromStdin() { |
| 289 static const int kBufferSize = 256; | 246 static const int kBufferSize = 256; |
| 290 char buffer[kBufferSize]; | 247 char buffer[kBufferSize]; |
| 291 Handle<String> accumulator = String::New(""); | 248 Handle<String> accumulator = String::New(""); |
| 292 int length; | 249 int length; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 } | 270 } |
| 314 } | 271 } |
| 315 } | 272 } |
| 316 | 273 |
| 317 | 274 |
| 318 Handle<Value> Shell::Load(const Arguments& args) { | 275 Handle<Value> Shell::Load(const Arguments& args) { |
| 319 for (int i = 0; i < args.Length(); i++) { | 276 for (int i = 0; i < args.Length(); i++) { |
| 320 HandleScope handle_scope; | 277 HandleScope handle_scope; |
| 321 String::Utf8Value file(args[i]); | 278 String::Utf8Value file(args[i]); |
| 322 if (*file == NULL) { | 279 if (*file == NULL) { |
| 323 return Throw("Error loading file"); | 280 return ThrowException(String::New("Error loading file")); |
| 324 } | 281 } |
| 325 Handle<String> source = ReadFile(*file); | 282 Handle<String> source = ReadFile(*file); |
| 326 if (source.IsEmpty()) { | 283 if (source.IsEmpty()) { |
| 327 return Throw("Error loading file"); | 284 return ThrowException(String::New("Error loading file")); |
| 328 } | 285 } |
| 329 if (!ExecuteString(source, String::New(*file), false, true)) { | 286 if (!ExecuteString(source, String::New(*file), false, true)) { |
| 330 return Throw("Error executing file"); | 287 return ThrowException(String::New("Error executing file")); |
| 331 } | 288 } |
| 332 } | 289 } |
| 333 return Undefined(); | 290 return Undefined(); |
| 334 } | 291 } |
| 335 | 292 |
| 336 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) { | 293 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) { |
| 337 if (value_in->IsInt32()) { | 294 if (value_in->IsInt32()) { |
| 338 return value_in->Int32Value(); | 295 return value_in->Int32Value(); |
| 339 } | 296 } |
| 340 | 297 |
| 341 Local<Value> number = value_in->ToNumber(); | 298 Local<Value> number = value_in->ToNumber(); |
| 342 if (try_catch->HasCaught()) return 0; | 299 if (try_catch->HasCaught()) return 0; |
| 343 | 300 |
| 344 ASSERT(number->IsNumber()); | 301 ASSERT(number->IsNumber()); |
| 345 Local<Int32> int32 = number->ToInt32(); | 302 Local<Int32> int32 = number->ToInt32(); |
| 346 if (try_catch->HasCaught() || int32.IsEmpty()) return 0; | 303 if (try_catch->HasCaught() || int32.IsEmpty()) return 0; |
| 347 | 304 |
| 348 int32_t value = int32->Int32Value(); | 305 int32_t value = int32->Int32Value(); |
| 349 if (try_catch->HasCaught()) return 0; | 306 if (try_catch->HasCaught()) return 0; |
| 350 | 307 |
| 351 return value; | 308 return value; |
| 352 } | 309 } |
| 353 | 310 |
| 354 | 311 |
| 355 static int32_t convertToUint(Local<Value> value_in, TryCatch* try_catch) { | 312 static int32_t convertToUint(Local<Value> value_in, TryCatch* try_catch) { |
| 356 int32_t raw_value = convertToInt(value_in, try_catch); | 313 int32_t raw_value = convertToInt(value_in, try_catch); |
| 357 if (try_catch->HasCaught()) return 0; | 314 if (try_catch->HasCaught()) return 0; |
| 358 | 315 |
| 359 if (raw_value < 0) { | 316 if (raw_value < 0) { |
| 360 Throw("Array length must not be negative."); | 317 ThrowException(String::New("Array length must not be negative.")); |
| 361 return 0; | 318 return 0; |
| 362 } | 319 } |
| 363 | 320 |
| 364 static const int kMaxLength = 0x3fffffff; | 321 static const int kMaxLength = 0x3fffffff; |
| 365 #ifndef V8_SHARED | 322 #ifndef V8_SHARED |
| 366 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); | 323 ASSERT(kMaxLength == i::ExternalArray::kMaxLength); |
| 367 #endif // V8_SHARED | 324 #endif // V8_SHARED |
| 368 if (raw_value > static_cast<int32_t>(kMaxLength)) { | 325 if (raw_value > static_cast<int32_t>(kMaxLength)) { |
| 369 Throw("Array length exceeds maximum length."); | 326 ThrowException( |
| 327 String::New("Array length exceeds maximum length.")); |
| 370 } | 328 } |
| 371 return raw_value; | 329 return raw_value; |
| 372 } | 330 } |
| 373 | 331 |
| 374 | 332 |
| 333 // TODO(rossberg): should replace these by proper uses of HasInstance, |
| 334 // once we figure out a good way to make the templates global. |
| 335 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; |
| 336 const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; |
| 337 |
| 338 |
| 375 Handle<Value> Shell::CreateExternalArrayBuffer(Handle<Object> buffer, | 339 Handle<Value> Shell::CreateExternalArrayBuffer(Handle<Object> buffer, |
| 376 int32_t length) { | 340 int32_t length) { |
| 377 static const int32_t kMaxSize = 0x7fffffff; | 341 static const int32_t kMaxSize = 0x7fffffff; |
| 378 // Make sure the total size fits into a (signed) int. | 342 // Make sure the total size fits into a (signed) int. |
| 379 if (length < 0 || length > kMaxSize) { | 343 if (length < 0 || length > kMaxSize) { |
| 380 return Throw("ArrayBuffer exceeds maximum size (2G)"); | 344 return ThrowException(String::New("ArrayBuffer exceeds maximum size (2G)")); |
| 381 } | 345 } |
| 382 uint8_t* data = new uint8_t[length]; | 346 uint8_t* data = new uint8_t[length]; |
| 383 if (data == NULL) { | 347 if (data == NULL) { |
| 384 return Throw("Memory allocation failed"); | 348 return ThrowException(String::New("Memory allocation failed")); |
| 385 } | 349 } |
| 386 memset(data, 0, length); | 350 memset(data, 0, length); |
| 387 | 351 |
| 388 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName, True()); | 352 buffer->SetHiddenValue(String::New(kArrayBufferMarkerPropName), True()); |
| 389 Persistent<Object> persistent_array = Persistent<Object>::New(buffer); | 353 Persistent<Object> persistent_array = Persistent<Object>::New(buffer); |
| 390 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 354 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); |
| 391 persistent_array.MarkIndependent(); | 355 persistent_array.MarkIndependent(); |
| 392 V8::AdjustAmountOfExternalAllocatedMemory(length); | 356 V8::AdjustAmountOfExternalAllocatedMemory(length); |
| 393 | 357 |
| 394 buffer->SetIndexedPropertiesToExternalArrayData( | 358 buffer->SetIndexedPropertiesToExternalArrayData( |
| 395 data, v8::kExternalByteArray, length); | 359 data, v8::kExternalByteArray, length); |
| 396 buffer->Set(Symbols::byteLength, Int32::New(length), ReadOnly); | 360 buffer->Set(String::New("byteLength"), Int32::New(length), ReadOnly); |
| 397 | 361 |
| 398 return buffer; | 362 return buffer; |
| 399 } | 363 } |
| 400 | 364 |
| 401 | 365 |
| 402 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { | 366 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { |
| 403 if (!args.IsConstructCall()) { | 367 if (!args.IsConstructCall()) { |
| 404 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; | 368 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; |
| 405 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i]; | 369 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i]; |
| 406 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args); | 370 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args); |
| 407 delete[] rec_args; | 371 delete[] rec_args; |
| 408 return result; | 372 return result; |
| 409 } | 373 } |
| 410 | 374 |
| 411 if (args.Length() == 0) { | 375 if (args.Length() == 0) { |
| 412 return Throw("ArrayBuffer constructor must have one argument"); | 376 return ThrowException( |
| 377 String::New("ArrayBuffer constructor must have one argument")); |
| 413 } | 378 } |
| 414 TryCatch try_catch; | 379 TryCatch try_catch; |
| 415 int32_t length = convertToUint(args[0], &try_catch); | 380 int32_t length = convertToUint(args[0], &try_catch); |
| 416 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 381 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 417 | 382 |
| 418 return CreateExternalArrayBuffer(args.This(), length); | 383 return CreateExternalArrayBuffer(args.This(), length); |
| 419 } | 384 } |
| 420 | 385 |
| 421 | 386 |
| 422 Handle<Object> Shell::CreateExternalArray(Handle<Object> array, | 387 Handle<Object> Shell::CreateExternalArray(Handle<Object> array, |
| 423 Handle<Object> buffer, | 388 Handle<Object> buffer, |
| 424 ExternalArrayType type, | 389 ExternalArrayType type, |
| 425 int32_t length, | 390 int32_t length, |
| 426 int32_t byteLength, | 391 int32_t byteLength, |
| 427 int32_t byteOffset, | 392 int32_t byteOffset, |
| 428 int32_t element_size) { | 393 int32_t element_size) { |
| 429 ASSERT(element_size == 1 || element_size == 2 || | 394 ASSERT(element_size == 1 || element_size == 2 || |
| 430 element_size == 4 || element_size == 8); | 395 element_size == 4 || element_size == 8); |
| 431 ASSERT(byteLength == length * element_size); | 396 ASSERT(byteLength == length * element_size); |
| 432 | 397 |
| 433 void* data = buffer->GetIndexedPropertiesExternalArrayData(); | 398 void* data = buffer->GetIndexedPropertiesExternalArrayData(); |
| 434 ASSERT(data != NULL); | 399 ASSERT(data != NULL); |
| 435 | 400 |
| 436 array->SetIndexedPropertiesToExternalArrayData( | 401 array->SetIndexedPropertiesToExternalArrayData( |
| 437 static_cast<uint8_t*>(data) + byteOffset, type, length); | 402 static_cast<uint8_t*>(data) + byteOffset, type, length); |
| 438 array->SetHiddenValue(Symbols::ArrayMarkerPropName, Int32::New(type)); | 403 array->SetHiddenValue(String::New(kArrayMarkerPropName), Int32::New(type)); |
| 439 array->Set(Symbols::byteLength, Int32::New(byteLength), ReadOnly); | 404 array->Set(String::New("byteLength"), Int32::New(byteLength), ReadOnly); |
| 440 array->Set(Symbols::byteOffset, Int32::New(byteOffset), ReadOnly); | 405 array->Set(String::New("byteOffset"), Int32::New(byteOffset), ReadOnly); |
| 441 array->Set(Symbols::length, Int32::New(length), ReadOnly); | 406 array->Set(String::New("length"), Int32::New(length), ReadOnly); |
| 442 array->Set(Symbols::BYTES_PER_ELEMENT, Int32::New(element_size)); | 407 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); |
| 443 array->Set(Symbols::buffer, buffer, ReadOnly); | 408 array->Set(String::New("buffer"), buffer, ReadOnly); |
| 444 | 409 |
| 445 return array; | 410 return array; |
| 446 } | 411 } |
| 447 | 412 |
| 448 | 413 |
| 449 Handle<Value> Shell::CreateExternalArray(const Arguments& args, | 414 Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
| 450 ExternalArrayType type, | 415 ExternalArrayType type, |
| 451 int32_t element_size) { | 416 int32_t element_size) { |
| 452 if (!args.IsConstructCall()) { | 417 if (!args.IsConstructCall()) { |
| 453 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; | 418 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 467 // TypedArray(TypedArray array) | 432 // TypedArray(TypedArray array) |
| 468 // TypedArray(ArrayBuffer buffer, | 433 // TypedArray(ArrayBuffer buffer, |
| 469 // optional unsigned long byteOffset, | 434 // optional unsigned long byteOffset, |
| 470 // optional unsigned long length) | 435 // optional unsigned long length) |
| 471 Handle<Object> buffer; | 436 Handle<Object> buffer; |
| 472 int32_t length; | 437 int32_t length; |
| 473 int32_t byteLength; | 438 int32_t byteLength; |
| 474 int32_t byteOffset; | 439 int32_t byteOffset; |
| 475 bool init_from_array = false; | 440 bool init_from_array = false; |
| 476 if (args.Length() == 0) { | 441 if (args.Length() == 0) { |
| 477 return Throw("Array constructor must have at least one argument"); | 442 return ThrowException( |
| 443 String::New("Array constructor must have at least one argument")); |
| 478 } | 444 } |
| 479 if (args[0]->IsObject() && | 445 if (args[0]->IsObject() && |
| 480 !args[0]->ToObject()->GetHiddenValue( | 446 !args[0]->ToObject()->GetHiddenValue( |
| 481 Symbols::ArrayBufferMarkerPropName).IsEmpty()) { | 447 String::New(kArrayBufferMarkerPropName)).IsEmpty()) { |
| 482 // Construct from ArrayBuffer. | 448 // Construct from ArrayBuffer. |
| 483 buffer = args[0]->ToObject(); | 449 buffer = args[0]->ToObject(); |
| 484 int32_t bufferLength = | 450 int32_t bufferLength = |
| 485 convertToUint(buffer->Get(Symbols::byteLength), &try_catch); | 451 convertToUint(buffer->Get(String::New("byteLength")), &try_catch); |
| 486 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 452 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 487 | 453 |
| 488 if (args.Length() < 2 || args[1]->IsUndefined()) { | 454 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 489 byteOffset = 0; | 455 byteOffset = 0; |
| 490 } else { | 456 } else { |
| 491 byteOffset = convertToUint(args[1], &try_catch); | 457 byteOffset = convertToUint(args[1], &try_catch); |
| 492 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 458 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 493 if (byteOffset > bufferLength) { | 459 if (byteOffset > bufferLength) { |
| 494 return Throw("byteOffset out of bounds"); | 460 return ThrowException(String::New("byteOffset out of bounds")); |
| 495 } | 461 } |
| 496 if (byteOffset % element_size != 0) { | 462 if (byteOffset % element_size != 0) { |
| 497 return Throw("byteOffset must be multiple of element size"); | 463 return ThrowException( |
| 464 String::New("byteOffset must be multiple of element size")); |
| 498 } | 465 } |
| 499 } | 466 } |
| 500 | 467 |
| 501 if (args.Length() < 3 || args[2]->IsUndefined()) { | 468 if (args.Length() < 3 || args[2]->IsUndefined()) { |
| 502 byteLength = bufferLength - byteOffset; | 469 byteLength = bufferLength - byteOffset; |
| 503 length = byteLength / element_size; | 470 length = byteLength / element_size; |
| 504 if (byteLength % element_size != 0) { | 471 if (byteLength % element_size != 0) { |
| 505 return Throw("buffer size must be multiple of element size"); | 472 return ThrowException( |
| 473 String::New("buffer size must be multiple of element size")); |
| 506 } | 474 } |
| 507 } else { | 475 } else { |
| 508 length = convertToUint(args[2], &try_catch); | 476 length = convertToUint(args[2], &try_catch); |
| 509 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 477 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 510 byteLength = length * element_size; | 478 byteLength = length * element_size; |
| 511 if (byteOffset + byteLength > bufferLength) { | 479 if (byteOffset + byteLength > bufferLength) { |
| 512 return Throw("length out of bounds"); | 480 return ThrowException(String::New("length out of bounds")); |
| 513 } | 481 } |
| 514 } | 482 } |
| 515 } else { | 483 } else { |
| 516 if (args[0]->IsObject() && | 484 if (args[0]->IsObject() && |
| 517 args[0]->ToObject()->Has(Symbols::length)) { | 485 args[0]->ToObject()->Has(String::New("length"))) { |
| 518 // Construct from array. | 486 // Construct from array. |
| 519 length = convertToUint( | 487 length = convertToUint( |
| 520 args[0]->ToObject()->Get(Symbols::length), &try_catch); | 488 args[0]->ToObject()->Get(String::New("length")), &try_catch); |
| 521 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 489 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 522 init_from_array = true; | 490 init_from_array = true; |
| 523 } else { | 491 } else { |
| 524 // Construct from size. | 492 // Construct from size. |
| 525 length = convertToUint(args[0], &try_catch); | 493 length = convertToUint(args[0], &try_catch); |
| 526 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 494 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 527 } | 495 } |
| 528 byteLength = length * element_size; | 496 byteLength = length * element_size; |
| 529 byteOffset = 0; | 497 byteOffset = 0; |
| 530 | 498 |
| 531 Handle<Object> global = Context::GetCurrent()->Global(); | 499 Handle<Object> global = Context::GetCurrent()->Global(); |
| 532 Handle<Value> array_buffer = global->Get(Symbols::ArrayBuffer); | 500 Handle<Value> array_buffer = global->Get(String::New("ArrayBuffer")); |
| 533 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); | 501 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); |
| 534 Handle<Value> buffer_args[] = { Uint32::New(byteLength) }; | 502 Handle<Value> buffer_args[] = { Uint32::New(byteLength) }; |
| 535 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( | 503 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( |
| 536 1, buffer_args); | 504 1, buffer_args); |
| 537 if (try_catch.HasCaught()) return result; | 505 if (try_catch.HasCaught()) return result; |
| 538 buffer = result->ToObject(); | 506 buffer = result->ToObject(); |
| 539 } | 507 } |
| 540 | 508 |
| 541 Handle<Object> array = CreateExternalArray( | 509 Handle<Object> array = CreateExternalArray( |
| 542 args.This(), buffer, type, length, byteLength, byteOffset, element_size); | 510 args.This(), buffer, type, length, byteLength, byteOffset, element_size); |
| 543 | 511 |
| 544 if (init_from_array) { | 512 if (init_from_array) { |
| 545 Handle<Object> init = args[0]->ToObject(); | 513 Handle<Object> init = args[0]->ToObject(); |
| 546 for (int i = 0; i < length; ++i) array->Set(i, init->Get(i)); | 514 for (int i = 0; i < length; ++i) array->Set(i, init->Get(i)); |
| 547 } | 515 } |
| 548 | 516 |
| 549 return array; | 517 return array; |
| 550 } | 518 } |
| 551 | 519 |
| 552 | 520 |
| 553 Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) { | 521 Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) { |
| 554 TryCatch try_catch; | 522 TryCatch try_catch; |
| 555 | 523 |
| 556 if (!args.This()->IsObject()) { | 524 if (!args.This()->IsObject()) { |
| 557 return Throw("'slice' invoked on non-object receiver"); | 525 return ThrowException( |
| 526 String::New("'slice' invoked on non-object receiver")); |
| 558 } | 527 } |
| 559 | 528 |
| 560 Local<Object> self = args.This(); | 529 Local<Object> self = args.This(); |
| 561 Local<Value> marker = | 530 Local<Value> marker = |
| 562 self->GetHiddenValue(Symbols::ArrayBufferMarkerPropName); | 531 self->GetHiddenValue(String::New(kArrayBufferMarkerPropName)); |
| 563 if (marker.IsEmpty()) { | 532 if (marker.IsEmpty()) { |
| 564 return Throw("'slice' invoked on wrong receiver type"); | 533 return ThrowException( |
| 534 String::New("'slice' invoked on wrong receiver type")); |
| 565 } | 535 } |
| 566 | 536 |
| 567 int32_t length = | 537 int32_t length = |
| 568 convertToUint(self->Get(Symbols::byteLength), &try_catch); | 538 convertToUint(self->Get(String::New("byteLength")), &try_catch); |
| 569 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 539 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 570 | 540 |
| 571 if (args.Length() == 0) { | 541 if (args.Length() == 0) { |
| 572 return Throw("'slice' must have at least one argument"); | 542 return ThrowException( |
| 543 String::New("'slice' must have at least one argument")); |
| 573 } | 544 } |
| 574 int32_t begin = convertToInt(args[0], &try_catch); | 545 int32_t begin = convertToInt(args[0], &try_catch); |
| 575 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 546 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 576 if (begin < 0) begin += length; | 547 if (begin < 0) begin += length; |
| 577 if (begin < 0) begin = 0; | 548 if (begin < 0) begin = 0; |
| 578 if (begin > length) begin = length; | 549 if (begin > length) begin = length; |
| 579 | 550 |
| 580 int32_t end; | 551 int32_t end; |
| 581 if (args.Length() < 2 || args[1]->IsUndefined()) { | 552 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 582 end = length; | 553 end = length; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 601 memcpy(dest, src, end - begin); | 572 memcpy(dest, src, end - begin); |
| 602 | 573 |
| 603 return buffer; | 574 return buffer; |
| 604 } | 575 } |
| 605 | 576 |
| 606 | 577 |
| 607 Handle<Value> Shell::ArraySubArray(const Arguments& args) { | 578 Handle<Value> Shell::ArraySubArray(const Arguments& args) { |
| 608 TryCatch try_catch; | 579 TryCatch try_catch; |
| 609 | 580 |
| 610 if (!args.This()->IsObject()) { | 581 if (!args.This()->IsObject()) { |
| 611 return Throw("'subarray' invoked on non-object receiver"); | 582 return ThrowException( |
| 583 String::New("'subarray' invoked on non-object receiver")); |
| 612 } | 584 } |
| 613 | 585 |
| 614 Local<Object> self = args.This(); | 586 Local<Object> self = args.This(); |
| 615 Local<Value> marker = self->GetHiddenValue(Symbols::ArrayMarkerPropName); | 587 Local<Value> marker = self->GetHiddenValue(String::New(kArrayMarkerPropName)); |
| 616 if (marker.IsEmpty()) { | 588 if (marker.IsEmpty()) { |
| 617 return Throw("'subarray' invoked on wrong receiver type"); | 589 return ThrowException( |
| 590 String::New("'subarray' invoked on wrong receiver type")); |
| 618 } | 591 } |
| 619 | 592 |
| 620 Handle<Object> buffer = self->Get(Symbols::buffer)->ToObject(); | 593 Handle<Object> buffer = self->Get(String::New("buffer"))->ToObject(); |
| 621 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 594 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 622 int32_t length = | 595 int32_t length = |
| 623 convertToUint(self->Get(Symbols::length), &try_catch); | 596 convertToUint(self->Get(String::New("length")), &try_catch); |
| 624 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 597 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 625 int32_t byteOffset = | 598 int32_t byteOffset = |
| 626 convertToUint(self->Get(Symbols::byteOffset), &try_catch); | 599 convertToUint(self->Get(String::New("byteOffset")), &try_catch); |
| 627 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 600 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 628 int32_t element_size = | 601 int32_t element_size = |
| 629 convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT), &try_catch); | 602 convertToUint(self->Get(String::New("BYTES_PER_ELEMENT")), &try_catch); |
| 630 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 603 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 631 | 604 |
| 632 if (args.Length() == 0) { | 605 if (args.Length() == 0) { |
| 633 return Throw("'subarray' must have at least one argument"); | 606 return ThrowException( |
| 607 String::New("'subarray' must have at least one argument")); |
| 634 } | 608 } |
| 635 int32_t begin = convertToInt(args[0], &try_catch); | 609 int32_t begin = convertToInt(args[0], &try_catch); |
| 636 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 610 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 637 if (begin < 0) begin += length; | 611 if (begin < 0) begin += length; |
| 638 if (begin < 0) begin = 0; | 612 if (begin < 0) begin = 0; |
| 639 if (begin > length) begin = length; | 613 if (begin > length) begin = length; |
| 640 | 614 |
| 641 int32_t end; | 615 int32_t end; |
| 642 if (args.Length() < 2 || args[1]->IsUndefined()) { | 616 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 643 end = length; | 617 end = length; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 658 buffer, Uint32::New(byteOffset), Uint32::New(length) | 632 buffer, Uint32::New(byteOffset), Uint32::New(length) |
| 659 }; | 633 }; |
| 660 return constructor->NewInstance(3, construct_args); | 634 return constructor->NewInstance(3, construct_args); |
| 661 } | 635 } |
| 662 | 636 |
| 663 | 637 |
| 664 Handle<Value> Shell::ArraySet(const Arguments& args) { | 638 Handle<Value> Shell::ArraySet(const Arguments& args) { |
| 665 TryCatch try_catch; | 639 TryCatch try_catch; |
| 666 | 640 |
| 667 if (!args.This()->IsObject()) { | 641 if (!args.This()->IsObject()) { |
| 668 return Throw("'set' invoked on non-object receiver"); | 642 return ThrowException( |
| 643 String::New("'set' invoked on non-object receiver")); |
| 669 } | 644 } |
| 670 | 645 |
| 671 Local<Object> self = args.This(); | 646 Local<Object> self = args.This(); |
| 672 Local<Value> marker = self->GetHiddenValue(Symbols::ArrayMarkerPropName); | 647 Local<Value> marker = self->GetHiddenValue(String::New(kArrayMarkerPropName)); |
| 673 if (marker.IsEmpty()) { | 648 if (marker.IsEmpty()) { |
| 674 return Throw("'set' invoked on wrong receiver type"); | 649 return ThrowException( |
| 650 String::New("'set' invoked on wrong receiver type")); |
| 675 } | 651 } |
| 676 int32_t length = | 652 int32_t length = |
| 677 convertToUint(self->Get(Symbols::length), &try_catch); | 653 convertToUint(self->Get(String::New("length")), &try_catch); |
| 678 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 654 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 679 int32_t element_size = | 655 int32_t element_size = |
| 680 convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT), &try_catch); | 656 convertToUint(self->Get(String::New("BYTES_PER_ELEMENT")), &try_catch); |
| 681 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 657 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 682 | 658 |
| 683 if (args.Length() == 0) { | 659 if (args.Length() == 0) { |
| 684 return Throw("'set' must have at least one argument"); | 660 return ThrowException( |
| 661 String::New("'set' must have at least one argument")); |
| 685 } | 662 } |
| 686 if (!args[0]->IsObject() || | 663 if (!args[0]->IsObject() || |
| 687 !args[0]->ToObject()->Has(Symbols::length)) { | 664 !args[0]->ToObject()->Has(String::New("length"))) { |
| 688 return Throw("'set' invoked with non-array argument"); | 665 return ThrowException( |
| 666 String::New("'set' invoked with non-array argument")); |
| 689 } | 667 } |
| 690 Handle<Object> source = args[0]->ToObject(); | 668 Handle<Object> source = args[0]->ToObject(); |
| 691 int32_t source_length = | 669 int32_t source_length = |
| 692 convertToUint(source->Get(Symbols::length), &try_catch); | 670 convertToUint(source->Get(String::New("length")), &try_catch); |
| 693 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 671 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 694 | 672 |
| 695 int32_t offset; | 673 int32_t offset; |
| 696 if (args.Length() < 2 || args[1]->IsUndefined()) { | 674 if (args.Length() < 2 || args[1]->IsUndefined()) { |
| 697 offset = 0; | 675 offset = 0; |
| 698 } else { | 676 } else { |
| 699 offset = convertToUint(args[1], &try_catch); | 677 offset = convertToUint(args[1], &try_catch); |
| 700 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 678 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 701 } | 679 } |
| 702 if (offset + source_length > length) { | 680 if (offset + source_length > length) { |
| 703 return Throw("offset or source length out of bounds"); | 681 return ThrowException(String::New("offset or source length out of bounds")); |
| 704 } | 682 } |
| 705 | 683 |
| 706 int32_t source_element_size; | 684 int32_t source_element_size; |
| 707 if (source->GetHiddenValue(Symbols::ArrayMarkerPropName).IsEmpty()) { | 685 if (source->GetHiddenValue(String::New(kArrayMarkerPropName)).IsEmpty()) { |
| 708 source_element_size = 0; | 686 source_element_size = 0; |
| 709 } else { | 687 } else { |
| 710 source_element_size = | 688 source_element_size = |
| 711 convertToUint(source->Get(Symbols::BYTES_PER_ELEMENT), &try_catch); | 689 convertToUint(source->Get(String::New("BYTES_PER_ELEMENT")), &try_catch); |
| 712 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 690 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 713 } | 691 } |
| 714 | 692 |
| 715 if (element_size == source_element_size && | 693 if (element_size == source_element_size && |
| 716 self->GetConstructor()->StrictEquals(source->GetConstructor())) { | 694 self->GetConstructor()->StrictEquals(source->GetConstructor())) { |
| 717 // Use memmove on the array buffers. | 695 // Use memmove on the array buffers. |
| 718 Handle<Object> buffer = self->Get(Symbols::buffer)->ToObject(); | 696 Handle<Object> buffer = self->Get(String::New("buffer"))->ToObject(); |
| 719 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 697 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 720 Handle<Object> source_buffer = | 698 Handle<Object> source_buffer = |
| 721 source->Get(Symbols::buffer)->ToObject(); | 699 source->Get(String::New("buffer"))->ToObject(); |
| 722 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 700 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 723 int32_t byteOffset = | 701 int32_t byteOffset = |
| 724 convertToUint(self->Get(Symbols::byteOffset), &try_catch); | 702 convertToUint(self->Get(String::New("byteOffset")), &try_catch); |
| 725 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 703 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 726 int32_t source_byteOffset = | 704 int32_t source_byteOffset = |
| 727 convertToUint(source->Get(Symbols::byteOffset), &try_catch); | 705 convertToUint(source->Get(String::New("byteOffset")), &try_catch); |
| 728 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 706 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 729 | 707 |
| 730 uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>( | 708 uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>( |
| 731 buffer->GetIndexedPropertiesExternalArrayData()); | 709 buffer->GetIndexedPropertiesExternalArrayData()); |
| 732 uint8_t* src = source_byteOffset + static_cast<uint8_t*>( | 710 uint8_t* src = source_byteOffset + static_cast<uint8_t*>( |
| 733 source_buffer->GetIndexedPropertiesExternalArrayData()); | 711 source_buffer->GetIndexedPropertiesExternalArrayData()); |
| 734 memmove(dest, src, source_length * element_size); | 712 memmove(dest, src, source_length * element_size); |
| 735 } else if (source_element_size == 0) { | 713 } else if (source_element_size == 0) { |
| 736 // Source is not a typed array, copy element-wise sequentially. | 714 // Source is not a typed array, copy element-wise sequentially. |
| 737 for (int i = 0; i < source_length; ++i) { | 715 for (int i = 0; i < source_length; ++i) { |
| 738 self->Set(offset + i, source->Get(i)); | 716 self->Set(offset + i, source->Get(i)); |
| 739 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 717 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 740 } | 718 } |
| 741 } else { | 719 } else { |
| 742 // Need to copy element-wise to make the right conversions. | 720 // Need to copy element-wise to make the right conversions. |
| 743 Handle<Object> buffer = self->Get(Symbols::buffer)->ToObject(); | 721 Handle<Object> buffer = self->Get(String::New("buffer"))->ToObject(); |
| 744 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 722 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 745 Handle<Object> source_buffer = | 723 Handle<Object> source_buffer = |
| 746 source->Get(Symbols::buffer)->ToObject(); | 724 source->Get(String::New("buffer"))->ToObject(); |
| 747 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 725 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 748 | 726 |
| 749 if (buffer->StrictEquals(source_buffer)) { | 727 if (buffer->StrictEquals(source_buffer)) { |
| 750 // Same backing store, need to handle overlap correctly. | 728 // Same backing store, need to handle overlap correctly. |
| 751 // This gets a bit tricky in the case of different element sizes | 729 // This gets a bit tricky in the case of different element sizes |
| 752 // (which, of course, is extremely unlikely to ever occur in practice). | 730 // (which, of course, is extremely unlikely to ever occur in practice). |
| 753 int32_t byteOffset = | 731 int32_t byteOffset = |
| 754 convertToUint(self->Get(Symbols::byteOffset), &try_catch); | 732 convertToUint(self->Get(String::New("byteOffset")), &try_catch); |
| 755 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 733 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 756 int32_t source_byteOffset = | 734 int32_t source_byteOffset = |
| 757 convertToUint(source->Get(Symbols::byteOffset), &try_catch); | 735 convertToUint(source->Get(String::New("byteOffset")), &try_catch); |
| 758 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 736 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
| 759 | 737 |
| 760 // Copy as much as we can from left to right. | 738 // Copy as much as we can from left to right. |
| 761 int i = 0; | 739 int i = 0; |
| 762 int32_t next_dest_offset = byteOffset + (offset + 1) * element_size; | 740 int32_t next_dest_offset = byteOffset + (offset + 1) * element_size; |
| 763 int32_t next_src_offset = source_byteOffset + source_element_size; | 741 int32_t next_src_offset = source_byteOffset + source_element_size; |
| 764 while (i < length && next_dest_offset <= next_src_offset) { | 742 while (i < length && next_dest_offset <= next_src_offset) { |
| 765 self->Set(offset + i, source->Get(i)); | 743 self->Set(offset + i, source->Get(i)); |
| 766 ++i; | 744 ++i; |
| 767 next_dest_offset += element_size; | 745 next_dest_offset += element_size; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 794 } | 772 } |
| 795 } | 773 } |
| 796 | 774 |
| 797 return Undefined(); | 775 return Undefined(); |
| 798 } | 776 } |
| 799 | 777 |
| 800 | 778 |
| 801 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 779 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
| 802 HandleScope scope; | 780 HandleScope scope; |
| 803 int32_t length = | 781 int32_t length = |
| 804 object->ToObject()->Get(Symbols::byteLength)->Uint32Value(); | 782 object->ToObject()->Get(String::New("byteLength"))->Uint32Value(); |
| 805 V8::AdjustAmountOfExternalAllocatedMemory(-length); | 783 V8::AdjustAmountOfExternalAllocatedMemory(-length); |
| 806 delete[] static_cast<uint8_t*>(data); | 784 delete[] static_cast<uint8_t*>(data); |
| 807 object.Dispose(); | 785 object.Dispose(); |
| 808 } | 786 } |
| 809 | 787 |
| 810 | 788 |
| 811 Handle<Value> Shell::Int8Array(const Arguments& args) { | 789 Handle<Value> Shell::Int8Array(const Arguments& args) { |
| 812 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); | 790 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); |
| 813 } | 791 } |
| 814 | 792 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 1158 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
| 1181 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 1159 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
| 1182 global_template->Set(String::New("enableProfiler"), | 1160 global_template->Set(String::New("enableProfiler"), |
| 1183 FunctionTemplate::New(EnableProfiler)); | 1161 FunctionTemplate::New(EnableProfiler)); |
| 1184 global_template->Set(String::New("disableProfiler"), | 1162 global_template->Set(String::New("disableProfiler"), |
| 1185 FunctionTemplate::New(DisableProfiler)); | 1163 FunctionTemplate::New(DisableProfiler)); |
| 1186 | 1164 |
| 1187 // Bind the handlers for external arrays. | 1165 // Bind the handlers for external arrays. |
| 1188 PropertyAttribute attr = | 1166 PropertyAttribute attr = |
| 1189 static_cast<PropertyAttribute>(ReadOnly | DontDelete); | 1167 static_cast<PropertyAttribute>(ReadOnly | DontDelete); |
| 1190 global_template->Set(Symbols::ArrayBuffer, | 1168 global_template->Set(String::New("ArrayBuffer"), |
| 1191 CreateArrayBufferTemplate(ArrayBuffer), attr); | 1169 CreateArrayBufferTemplate(ArrayBuffer), attr); |
| 1192 global_template->Set(String::New("Int8Array"), | 1170 global_template->Set(String::New("Int8Array"), |
| 1193 CreateArrayTemplate(Int8Array), attr); | 1171 CreateArrayTemplate(Int8Array), attr); |
| 1194 global_template->Set(String::New("Uint8Array"), | 1172 global_template->Set(String::New("Uint8Array"), |
| 1195 CreateArrayTemplate(Uint8Array), attr); | 1173 CreateArrayTemplate(Uint8Array), attr); |
| 1196 global_template->Set(String::New("Int16Array"), | 1174 global_template->Set(String::New("Int16Array"), |
| 1197 CreateArrayTemplate(Int16Array), attr); | 1175 CreateArrayTemplate(Int16Array), attr); |
| 1198 global_template->Set(String::New("Uint16Array"), | 1176 global_template->Set(String::New("Uint16Array"), |
| 1199 CreateArrayTemplate(Uint16Array), attr); | 1177 CreateArrayTemplate(Uint16Array), attr); |
| 1200 global_template->Set(String::New("Int32Array"), | 1178 global_template->Set(String::New("Int32Array"), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 Shell::counter_map_ = new CounterMap(); | 1216 Shell::counter_map_ = new CounterMap(); |
| 1239 // Set up counters | 1217 // Set up counters |
| 1240 if (i::StrLength(i::FLAG_map_counters) != 0) | 1218 if (i::StrLength(i::FLAG_map_counters) != 0) |
| 1241 MapCounters(i::FLAG_map_counters); | 1219 MapCounters(i::FLAG_map_counters); |
| 1242 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { | 1220 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { |
| 1243 V8::SetCounterFunction(LookupCounter); | 1221 V8::SetCounterFunction(LookupCounter); |
| 1244 V8::SetCreateHistogramFunction(CreateHistogram); | 1222 V8::SetCreateHistogramFunction(CreateHistogram); |
| 1245 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 1223 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| 1246 } | 1224 } |
| 1247 #endif // V8_SHARED | 1225 #endif // V8_SHARED |
| 1248 | |
| 1249 Symbols::Initialize(); | |
| 1250 if (options.test_shell) return; | 1226 if (options.test_shell) return; |
| 1251 | 1227 |
| 1252 #ifndef V8_SHARED | 1228 #ifndef V8_SHARED |
| 1253 Locker lock; | 1229 Locker lock; |
| 1254 HandleScope scope; | 1230 HandleScope scope; |
| 1255 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 1231 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| 1256 utility_context_ = Context::New(NULL, global_template); | 1232 utility_context_ = Context::New(NULL, global_template); |
| 1257 | 1233 |
| 1258 #ifdef ENABLE_DEBUGGER_SUPPORT | 1234 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1259 // Start the debugger agent if requested. | 1235 // Start the debugger agent if requested. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 *size_out = size; | 1374 *size_out = size; |
| 1399 return chars; | 1375 return chars; |
| 1400 } | 1376 } |
| 1401 | 1377 |
| 1402 | 1378 |
| 1403 Handle<Value> Shell::ReadBuffer(const Arguments& args) { | 1379 Handle<Value> Shell::ReadBuffer(const Arguments& args) { |
| 1404 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT | 1380 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT |
| 1405 String::Utf8Value filename(args[0]); | 1381 String::Utf8Value filename(args[0]); |
| 1406 int length; | 1382 int length; |
| 1407 if (*filename == NULL) { | 1383 if (*filename == NULL) { |
| 1408 return Throw("Error loading file"); | 1384 return ThrowException(String::New("Error loading file")); |
| 1409 } | 1385 } |
| 1410 | 1386 |
| 1411 uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length)); | 1387 uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length)); |
| 1412 if (data == NULL) { | 1388 if (data == NULL) { |
| 1413 return Throw("Error reading file"); | 1389 return ThrowException(String::New("Error reading file")); |
| 1414 } | 1390 } |
| 1415 Handle<Object> buffer = Object::New(); | 1391 Handle<Object> buffer = Object::New(); |
| 1416 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName, True()); | 1392 buffer->SetHiddenValue(String::New(kArrayBufferMarkerPropName), True()); |
| 1417 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer); | 1393 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer); |
| 1418 persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); | 1394 persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); |
| 1419 persistent_buffer.MarkIndependent(); | 1395 persistent_buffer.MarkIndependent(); |
| 1420 V8::AdjustAmountOfExternalAllocatedMemory(length); | 1396 V8::AdjustAmountOfExternalAllocatedMemory(length); |
| 1421 | 1397 |
| 1422 buffer->SetIndexedPropertiesToExternalArrayData( | 1398 buffer->SetIndexedPropertiesToExternalArrayData( |
| 1423 data, kExternalUnsignedByteArray, length); | 1399 data, kExternalUnsignedByteArray, length); |
| 1424 buffer->Set(Symbols::byteLength, | 1400 buffer->Set(String::New("byteLength"), |
| 1425 Int32::New(static_cast<int32_t>(length)), ReadOnly); | 1401 Int32::New(static_cast<int32_t>(length)), ReadOnly); |
| 1426 return buffer; | 1402 return buffer; |
| 1427 } | 1403 } |
| 1428 | 1404 |
| 1429 | 1405 |
| 1430 #ifndef V8_SHARED | 1406 #ifndef V8_SHARED |
| 1431 static char* ReadToken(char* data, char token) { | 1407 static char* ReadToken(char* data, char token) { |
| 1432 char* next = i::OS::StrChr(data, token); | 1408 char* next = i::OS::StrChr(data, token); |
| 1433 if (next != NULL) { | 1409 if (next != NULL) { |
| 1434 *next = '\0'; | 1410 *next = '\0'; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 || !options.script_executed ) | 1888 || !options.script_executed ) |
| 1913 && !options.test_shell ) { | 1889 && !options.test_shell ) { |
| 1914 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 1890 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 1915 if (!i::FLAG_debugger) { | 1891 if (!i::FLAG_debugger) { |
| 1916 InstallUtilityScript(); | 1892 InstallUtilityScript(); |
| 1917 } | 1893 } |
| 1918 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1894 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1919 RunShell(); | 1895 RunShell(); |
| 1920 } | 1896 } |
| 1921 | 1897 |
| 1922 Symbols::TearDown(); | |
| 1923 V8::Dispose(); | 1898 V8::Dispose(); |
| 1924 | 1899 |
| 1925 #ifndef V8_SHARED | 1900 #ifndef V8_SHARED |
| 1926 OnExit(); | 1901 OnExit(); |
| 1927 #endif // V8_SHARED | 1902 #endif // V8_SHARED |
| 1928 | 1903 |
| 1929 return result; | 1904 return result; |
| 1930 } | 1905 } |
| 1931 | 1906 |
| 1932 } // namespace v8 | 1907 } // namespace v8 |
| 1933 | 1908 |
| 1934 | 1909 |
| 1935 #ifndef GOOGLE3 | 1910 #ifndef GOOGLE3 |
| 1936 int main(int argc, char* argv[]) { | 1911 int main(int argc, char* argv[]) { |
| 1937 return v8::Shell::Main(argc, argv); | 1912 return v8::Shell::Main(argc, argv); |
| 1938 } | 1913 } |
| 1939 #endif | 1914 #endif |
| OLD | NEW |