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 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2455 } | 2455 } |
2456 | 2456 |
2457 | 2457 |
2458 bool Value::IsNumberObject() const { | 2458 bool Value::IsNumberObject() const { |
2459 i::Isolate* isolate = i::Isolate::Current(); | 2459 i::Isolate* isolate = i::Isolate::Current(); |
2460 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2460 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2461 return obj->HasSpecificClassOf(isolate->heap()->Number_string()); | 2461 return obj->HasSpecificClassOf(isolate->heap()->Number_string()); |
2462 } | 2462 } |
2463 | 2463 |
2464 | 2464 |
2465 static i::Object* LookupBuiltin(i::Isolate* isolate, | |
2466 const char* builtin_name) { | |
2467 i::Handle<i::String> string = | |
2468 isolate->factory()->InternalizeUtf8String(builtin_name); | |
2469 i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); | |
2470 return builtins->GetPropertyNoExceptionThrown(*string); | |
2471 } | |
2472 | |
2473 | |
2474 static bool CheckConstructor(i::Isolate* isolate, | |
2475 i::Handle<i::JSObject> obj, | |
2476 const char* class_name) { | |
2477 i::Object* constr = obj->map()->constructor(); | |
2478 if (!constr->IsJSFunction()) return false; | |
2479 i::JSFunction* func = i::JSFunction::cast(constr); | |
2480 return func->shared()->native() && | |
2481 constr == LookupBuiltin(isolate, class_name); | |
2482 } | |
2483 | |
2484 | |
2485 bool Value::IsNativeError() const { | 2465 bool Value::IsNativeError() const { |
2486 i::Isolate* isolate = i::Isolate::Current(); | 2466 Local<Value> handle = Utils::ToLocal(Utils::OpenHandle(this)); |
2487 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2467 return Exception::NativeErrorType(handle) != Exception::kNoError; |
2488 if (obj->IsJSObject()) { | |
2489 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); | |
2490 return CheckConstructor(isolate, js_obj, "$Error") || | |
2491 CheckConstructor(isolate, js_obj, "$EvalError") || | |
2492 CheckConstructor(isolate, js_obj, "$RangeError") || | |
2493 CheckConstructor(isolate, js_obj, "$ReferenceError") || | |
2494 CheckConstructor(isolate, js_obj, "$SyntaxError") || | |
2495 CheckConstructor(isolate, js_obj, "$TypeError") || | |
2496 CheckConstructor(isolate, js_obj, "$URIError"); | |
2497 } else { | |
2498 return false; | |
2499 } | |
2500 } | 2468 } |
2501 | 2469 |
2502 | 2470 |
2503 bool Value::IsBooleanObject() const { | 2471 bool Value::IsBooleanObject() const { |
2504 i::Isolate* isolate = i::Isolate::Current(); | 2472 i::Isolate* isolate = i::Isolate::Current(); |
2505 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2473 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2506 return obj->HasSpecificClassOf(isolate->heap()->Boolean_string()); | 2474 return obj->HasSpecificClassOf(isolate->heap()->Boolean_string()); |
2507 } | 2475 } |
2508 | 2476 |
2509 | 2477 |
(...skipping 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6455 str_ = i::NewArray<uint16_t>(length_ + 1); | 6423 str_ = i::NewArray<uint16_t>(length_ + 1); |
6456 str->Write(str_); | 6424 str->Write(str_); |
6457 } | 6425 } |
6458 | 6426 |
6459 | 6427 |
6460 String::Value::~Value() { | 6428 String::Value::~Value() { |
6461 i::DeleteArray(str_); | 6429 i::DeleteArray(str_); |
6462 } | 6430 } |
6463 | 6431 |
6464 | 6432 |
6465 Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { | 6433 Exception::ErrorType Exception::NativeErrorType(Local<Value> value) { |
| 6434 i::Handle<i::Object> exception = Utils::OpenHandle(*value); |
| 6435 if (!exception->IsJSObject()) return kNoError; |
| 6436 i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(exception); |
| 6437 i::Isolate* isolate = js_obj->GetIsolate(); |
| 6438 i::LookupResult lookup(isolate); |
| 6439 js_obj->LocalLookup(isolate->heap()->error_type(), &lookup, false); |
| 6440 if (!lookup.IsFound()) return kNoError; |
| 6441 i::Object* val = lookup.GetLazyValue(); |
| 6442 if (!val->IsSmi() || val == isolate->heap()->the_hole_value()) { |
| 6443 return kNoError; |
| 6444 } |
| 6445 return static_cast<Exception::ErrorType>(i::Smi::cast(val)->value()); |
| 6446 } |
| 6447 |
| 6448 |
| 6449 static Local<Value> NewError(Exception::ErrorType error_type, |
| 6450 v8::Handle<v8::String> raw_message) { |
6466 i::Isolate* isolate = i::Isolate::Current(); | 6451 i::Isolate* isolate = i::Isolate::Current(); |
6467 LOG_API(isolate, "RangeError"); | 6452 LOG_API(isolate, "NewError"); |
6468 ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); | 6453 ON_BAILOUT(isolate, "v8::Exception::NewError()", return Local<Value>()); |
6469 ENTER_V8(isolate); | 6454 ENTER_V8(isolate); |
6470 i::Object* error; | 6455 i::Object* error; |
6471 { | 6456 { |
6472 i::HandleScope scope(isolate); | 6457 i::HandleScope scope(isolate); |
6473 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); | 6458 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
6474 i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); | 6459 i::Handle<i::Object> result; |
| 6460 switch (error_type) { |
| 6461 case Exception::kError: |
| 6462 result = isolate->factory()->NewError(message); |
| 6463 break; |
| 6464 case Exception::kTypeError: |
| 6465 result = isolate->factory()->NewTypeError(message); |
| 6466 break; |
| 6467 case Exception::kRangeError: |
| 6468 result = isolate->factory()->NewRangeError(message); |
| 6469 break; |
| 6470 case Exception::kSyntaxError: |
| 6471 result = isolate->factory()->NewSyntaxError(message); |
| 6472 break; |
| 6473 case Exception::kReferenceError: |
| 6474 result = isolate->factory()->NewReferenceError(message); |
| 6475 break; |
| 6476 case Exception::kStackOverflowError: |
| 6477 result = isolate->factory()->NewStackOverflowError(message); |
| 6478 break; |
| 6479 case Exception::kURIError: |
| 6480 result = isolate->factory()->NewURIError(message); |
| 6481 break; |
| 6482 case Exception::kEvalError: |
| 6483 result = isolate->factory()->NewEvalError(message); |
| 6484 break; |
| 6485 case Exception::kNoError: |
| 6486 UNREACHABLE(); |
| 6487 break; |
| 6488 } |
6475 error = *result; | 6489 error = *result; |
6476 } | 6490 } |
6477 i::Handle<i::Object> result(error, isolate); | 6491 i::Handle<i::Object> result(error, isolate); |
6478 return Utils::ToLocal(result); | |
6479 } | |
6480 | |
6481 | |
6482 Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { | |
6483 i::Isolate* isolate = i::Isolate::Current(); | |
6484 LOG_API(isolate, "ReferenceError"); | |
6485 ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); | |
6486 ENTER_V8(isolate); | |
6487 i::Object* error; | |
6488 { | |
6489 i::HandleScope scope(isolate); | |
6490 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); | |
6491 i::Handle<i::Object> result = | |
6492 isolate->factory()->NewReferenceError(message); | |
6493 error = *result; | |
6494 } | |
6495 i::Handle<i::Object> result(error, isolate); | |
6496 return Utils::ToLocal(result); | 6492 return Utils::ToLocal(result); |
6497 } | 6493 } |
6498 | 6494 |
6499 | 6495 |
| 6496 Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
| 6497 return NewError(kRangeError, raw_message); |
| 6498 } |
| 6499 |
| 6500 |
| 6501 Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
| 6502 return NewError(kReferenceError, raw_message); |
| 6503 } |
| 6504 |
| 6505 |
6500 Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { | 6506 Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
6501 i::Isolate* isolate = i::Isolate::Current(); | 6507 return NewError(kSyntaxError, raw_message); |
6502 LOG_API(isolate, "SyntaxError"); | |
6503 ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); | |
6504 ENTER_V8(isolate); | |
6505 i::Object* error; | |
6506 { | |
6507 i::HandleScope scope(isolate); | |
6508 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); | |
6509 i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); | |
6510 error = *result; | |
6511 } | |
6512 i::Handle<i::Object> result(error, isolate); | |
6513 return Utils::ToLocal(result); | |
6514 } | 6508 } |
6515 | 6509 |
6516 | 6510 |
6517 Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { | 6511 Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
6518 i::Isolate* isolate = i::Isolate::Current(); | 6512 return NewError(kTypeError, raw_message); |
6519 LOG_API(isolate, "TypeError"); | 6513 } |
6520 ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); | 6514 |
6521 ENTER_V8(isolate); | 6515 |
6522 i::Object* error; | 6516 Local<Value> Exception::EvalError(v8::Handle<v8::String> raw_message) { |
6523 { | 6517 return NewError(kEvalError, raw_message); |
6524 i::HandleScope scope(isolate); | 6518 } |
6525 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); | 6519 |
6526 i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); | 6520 |
6527 error = *result; | 6521 Local<Value> Exception::URIError(v8::Handle<v8::String> raw_message) { |
6528 } | 6522 return NewError(kURIError, raw_message); |
6529 i::Handle<i::Object> result(error, isolate); | |
6530 return Utils::ToLocal(result); | |
6531 } | 6523 } |
6532 | 6524 |
6533 | 6525 |
6534 Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { | 6526 Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
6535 i::Isolate* isolate = i::Isolate::Current(); | 6527 return NewError(kError, raw_message); |
6536 LOG_API(isolate, "Error"); | |
6537 ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); | |
6538 ENTER_V8(isolate); | |
6539 i::Object* error; | |
6540 { | |
6541 i::HandleScope scope(isolate); | |
6542 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); | |
6543 i::Handle<i::Object> result = isolate->factory()->NewError(message); | |
6544 error = *result; | |
6545 } | |
6546 i::Handle<i::Object> result(error, isolate); | |
6547 return Utils::ToLocal(result); | |
6548 } | 6528 } |
6549 | 6529 |
6550 | 6530 |
| 6531 Local<Value> Exception::StackOverflowError( |
| 6532 v8::Handle<v8::String> raw_message) { |
| 6533 return NewError(kStackOverflowError, raw_message); |
| 6534 } |
| 6535 |
| 6536 |
6551 // --- D e b u g S u p p o r t --- | 6537 // --- D e b u g S u p p o r t --- |
6552 | 6538 |
6553 #ifdef ENABLE_DEBUGGER_SUPPORT | 6539 #ifdef ENABLE_DEBUGGER_SUPPORT |
6554 | 6540 |
6555 bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { | 6541 bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
6556 i::Isolate* isolate = i::Isolate::Current(); | 6542 i::Isolate* isolate = i::Isolate::Current(); |
6557 EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); | 6543 EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
6558 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); | 6544 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
6559 ENTER_V8(isolate); | 6545 ENTER_V8(isolate); |
6560 i::HandleScope scope(isolate); | 6546 i::HandleScope scope(isolate); |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7377 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7363 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7378 Address callback_address = | 7364 Address callback_address = |
7379 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7365 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7380 VMState<EXTERNAL> state(isolate); | 7366 VMState<EXTERNAL> state(isolate); |
7381 ExternalCallbackScope call_scope(isolate, callback_address); | 7367 ExternalCallbackScope call_scope(isolate, callback_address); |
7382 callback(info); | 7368 callback(info); |
7383 } | 7369 } |
7384 | 7370 |
7385 | 7371 |
7386 } } // namespace v8::internal | 7372 } } // namespace v8::internal |
OLD | NEW |