| Index: src/api.cc
|
| diff --git a/src/api.cc b/src/api.cc
|
| index 2c7db3be1656f10d475dd8e1de71a89ed374cdd6..b5517622fab9ce013528e5c721dca5d2b2ee7e5d 100644
|
| --- a/src/api.cc
|
| +++ b/src/api.cc
|
| @@ -2462,41 +2462,9 @@ bool Value::IsNumberObject() const {
|
| }
|
|
|
|
|
| -static i::Object* LookupBuiltin(i::Isolate* isolate,
|
| - const char* builtin_name) {
|
| - i::Handle<i::String> string =
|
| - isolate->factory()->InternalizeUtf8String(builtin_name);
|
| - i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object();
|
| - return builtins->GetPropertyNoExceptionThrown(*string);
|
| -}
|
| -
|
| -
|
| -static bool CheckConstructor(i::Isolate* isolate,
|
| - i::Handle<i::JSObject> obj,
|
| - const char* class_name) {
|
| - i::Object* constr = obj->map()->constructor();
|
| - if (!constr->IsJSFunction()) return false;
|
| - i::JSFunction* func = i::JSFunction::cast(constr);
|
| - return func->shared()->native() &&
|
| - constr == LookupBuiltin(isolate, class_name);
|
| -}
|
| -
|
| -
|
| bool Value::IsNativeError() const {
|
| - i::Isolate* isolate = i::Isolate::Current();
|
| - i::Handle<i::Object> obj = Utils::OpenHandle(this);
|
| - if (obj->IsJSObject()) {
|
| - i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj));
|
| - return CheckConstructor(isolate, js_obj, "$Error") ||
|
| - CheckConstructor(isolate, js_obj, "$EvalError") ||
|
| - CheckConstructor(isolate, js_obj, "$RangeError") ||
|
| - CheckConstructor(isolate, js_obj, "$ReferenceError") ||
|
| - CheckConstructor(isolate, js_obj, "$SyntaxError") ||
|
| - CheckConstructor(isolate, js_obj, "$TypeError") ||
|
| - CheckConstructor(isolate, js_obj, "$URIError");
|
| - } else {
|
| - return false;
|
| - }
|
| + Local<Value> handle = Utils::ToLocal(Utils::OpenHandle(this));
|
| + return Exception::NativeErrorType(handle) != Exception::kNoError;
|
| }
|
|
|
|
|
| @@ -6462,34 +6430,62 @@ String::Value::~Value() {
|
| }
|
|
|
|
|
| -Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) {
|
| - i::Isolate* isolate = i::Isolate::Current();
|
| - LOG_API(isolate, "RangeError");
|
| - ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>());
|
| - ENTER_V8(isolate);
|
| - i::Object* error;
|
| - {
|
| - i::HandleScope scope(isolate);
|
| - i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
| - i::Handle<i::Object> result = isolate->factory()->NewRangeError(message);
|
| - error = *result;
|
| +Exception::ErrorType Exception::NativeErrorType(Local<Value> value) {
|
| + i::Handle<i::Object> exception = Utils::OpenHandle(*value);
|
| + if (!exception->IsJSObject()) return kNoError;
|
| + i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(exception);
|
| + i::Isolate* isolate = js_obj->GetIsolate();
|
| + i::LookupResult lookup(isolate);
|
| + js_obj->LocalLookup(isolate->heap()->error_type(), &lookup, false);
|
| + if (!lookup.IsFound()) return kNoError;
|
| + i::Object* val = lookup.GetLazyValue();
|
| + if (!val->IsSmi() || val == isolate->heap()->the_hole_value()) {
|
| + return kNoError;
|
| }
|
| - i::Handle<i::Object> result(error, isolate);
|
| - return Utils::ToLocal(result);
|
| + return static_cast<Exception::ErrorType>(i::Smi::cast(val)->value());
|
| }
|
|
|
|
|
| -Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) {
|
| +static Local<Value> NewError(Exception::ErrorType error_type,
|
| + v8::Handle<v8::String> raw_message) {
|
| i::Isolate* isolate = i::Isolate::Current();
|
| - LOG_API(isolate, "ReferenceError");
|
| - ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>());
|
| + LOG_API(isolate, "NewError");
|
| + ON_BAILOUT(isolate, "v8::Exception::NewError()", return Local<Value>());
|
| ENTER_V8(isolate);
|
| i::Object* error;
|
| {
|
| i::HandleScope scope(isolate);
|
| i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
| - i::Handle<i::Object> result =
|
| - isolate->factory()->NewReferenceError(message);
|
| + i::Handle<i::Object> result;
|
| + switch (error_type) {
|
| + case Exception::kError:
|
| + result = isolate->factory()->NewError(message);
|
| + break;
|
| + case Exception::kTypeError:
|
| + result = isolate->factory()->NewTypeError(message);
|
| + break;
|
| + case Exception::kRangeError:
|
| + result = isolate->factory()->NewRangeError(message);
|
| + break;
|
| + case Exception::kSyntaxError:
|
| + result = isolate->factory()->NewSyntaxError(message);
|
| + break;
|
| + case Exception::kReferenceError:
|
| + result = isolate->factory()->NewReferenceError(message);
|
| + break;
|
| + case Exception::kStackOverflowError:
|
| + result = isolate->factory()->NewStackOverflowError(message);
|
| + break;
|
| + case Exception::kURIError:
|
| + result = isolate->factory()->NewURIError(message);
|
| + break;
|
| + case Exception::kEvalError:
|
| + result = isolate->factory()->NewEvalError(message);
|
| + break;
|
| + case Exception::kNoError:
|
| + UNREACHABLE();
|
| + break;
|
| + }
|
| error = *result;
|
| }
|
| i::Handle<i::Object> result(error, isolate);
|
| @@ -6497,54 +6493,44 @@ Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) {
|
| }
|
|
|
|
|
| +Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) {
|
| + return NewError(kRangeError, raw_message);
|
| +}
|
| +
|
| +
|
| +Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) {
|
| + return NewError(kReferenceError, raw_message);
|
| +}
|
| +
|
| +
|
| Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) {
|
| - i::Isolate* isolate = i::Isolate::Current();
|
| - LOG_API(isolate, "SyntaxError");
|
| - ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>());
|
| - ENTER_V8(isolate);
|
| - i::Object* error;
|
| - {
|
| - i::HandleScope scope(isolate);
|
| - i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
| - i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message);
|
| - error = *result;
|
| - }
|
| - i::Handle<i::Object> result(error, isolate);
|
| - return Utils::ToLocal(result);
|
| + return NewError(kSyntaxError, raw_message);
|
| }
|
|
|
|
|
| Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) {
|
| - i::Isolate* isolate = i::Isolate::Current();
|
| - LOG_API(isolate, "TypeError");
|
| - ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>());
|
| - ENTER_V8(isolate);
|
| - i::Object* error;
|
| - {
|
| - i::HandleScope scope(isolate);
|
| - i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
| - i::Handle<i::Object> result = isolate->factory()->NewTypeError(message);
|
| - error = *result;
|
| - }
|
| - i::Handle<i::Object> result(error, isolate);
|
| - return Utils::ToLocal(result);
|
| + return NewError(kTypeError, raw_message);
|
| +}
|
| +
|
| +
|
| +Local<Value> Exception::EvalError(v8::Handle<v8::String> raw_message) {
|
| + return NewError(kEvalError, raw_message);
|
| +}
|
| +
|
| +
|
| +Local<Value> Exception::URIError(v8::Handle<v8::String> raw_message) {
|
| + return NewError(kURIError, raw_message);
|
| }
|
|
|
|
|
| Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) {
|
| - i::Isolate* isolate = i::Isolate::Current();
|
| - LOG_API(isolate, "Error");
|
| - ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>());
|
| - ENTER_V8(isolate);
|
| - i::Object* error;
|
| - {
|
| - i::HandleScope scope(isolate);
|
| - i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
|
| - i::Handle<i::Object> result = isolate->factory()->NewError(message);
|
| - error = *result;
|
| - }
|
| - i::Handle<i::Object> result(error, isolate);
|
| - return Utils::ToLocal(result);
|
| + return NewError(kError, raw_message);
|
| +}
|
| +
|
| +
|
| +Local<Value> Exception::StackOverflowError(
|
| + v8::Handle<v8::String> raw_message) {
|
| + return NewError(kStackOverflowError, raw_message);
|
| }
|
|
|
|
|
|
|