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