Commit a862f781 authored by yurys@chromium.org's avatar yurys@chromium.org

Added Message::GetScripOrigin.

Replaced Message::GetResourceName with GetScriptOrigin().ResourceName().

Now, GetScriptOrigin().ResourceName() function returns the resource name or sourceURL (from //# sourceURL=) for the script from where the function causing the error originates.

Method GetScriptResourceName() deprecated. Use GetScriptOrigin()->ResourceName() instead.

Function used in Blink: https://codereview.chromium.org/260513004/

R=yangguo@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/265593002

Patch from Alexey Kozyatinskiy <kozyatinskiy@google.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21893 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a685c2e0
......@@ -1108,6 +1108,12 @@ class V8_EXPORT Message {
Local<String> Get() const;
Local<String> GetSourceLine() const;
/**
* Returns the origin for the script from where the function causing the
* error originates.
*/
ScriptOrigin GetScriptOrigin() const;
/**
* Returns the resource name for the script from where the function causing
* the error originates.
......
......@@ -300,7 +300,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
printf("%s\n", exception_string);
} else {
// Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptResourceName());
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber();
printf("%s:%i: %s\n", filename_string, linenum, exception_string);
......
......@@ -358,7 +358,7 @@ void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
fprintf(stderr, "%s\n", exception_string);
} else {
// Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptResourceName());
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber();
fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);
......
......@@ -1944,19 +1944,28 @@ Local<String> Message::Get() const {
}
v8::Handle<Value> Message::GetScriptResourceName() const {
ScriptOrigin Message::GetScriptOrigin() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSMessageObject> message =
i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
// Return this.script.name.
i::Handle<i::JSValue> script =
i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
isolate));
i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(),
isolate);
return scope.Escape(Utils::ToLocal(resource_name));
i::Handle<i::Object> script_wraper =
i::Handle<i::Object>(message->script(), isolate);
i::Handle<i::JSValue> script_value =
i::Handle<i::JSValue>::cast(script_wraper);
i::Handle<i::Script> script(i::Script::cast(script_value->value()));
i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script));
v8::Isolate* v8_isolate =
reinterpret_cast<v8::Isolate*>(script->GetIsolate());
v8::ScriptOrigin origin(
Utils::ToLocal(scriptName),
v8::Integer::New(v8_isolate, script->line_offset()->value()),
v8::Integer::New(v8_isolate, script->column_offset()->value()));
return origin;
}
v8::Handle<Value> Message::GetScriptResourceName() const {
return GetScriptOrigin().ResourceName();
}
......
......@@ -561,7 +561,7 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
printf("%s\n", exception_string);
} else {
// Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptResourceName());
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber();
printf("%s:%i: %s\n", filename_string, linenum, exception_string);
......
......@@ -4153,7 +4153,7 @@ bool message_received;
static void check_message_0(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK_EQ(5.76, data->NumberValue());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue());
CHECK(!message->IsSharedCrossOrigin());
message_received = true;
}
......@@ -4227,7 +4227,7 @@ TEST(MessageHandler2) {
static void check_message_3(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK(message->IsSharedCrossOrigin());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue());
message_received = true;
}
......@@ -4256,7 +4256,7 @@ TEST(MessageHandler3) {
static void check_message_4(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK(!message->IsSharedCrossOrigin());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue());
message_received = true;
}
......@@ -4285,7 +4285,7 @@ TEST(MessageHandler4) {
static void check_message_5a(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK(message->IsSharedCrossOrigin());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue());
message_received = true;
}
......@@ -4293,7 +4293,7 @@ static void check_message_5a(v8::Handle<v8::Message> message,
static void check_message_5b(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK(!message->IsSharedCrossOrigin());
CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue());
message_received = true;
}
......@@ -5339,7 +5339,7 @@ TEST(TryCatchNested) {
void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
CHECK(try_catch->HasCaught());
Handle<Message> message = try_catch->Message();
Handle<Value> resource = message->GetScriptResourceName();
Handle<Value> resource = message->GetScriptOrigin().ResourceName();
CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner"));
CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()),
"Uncaught Error: a"));
......@@ -7110,8 +7110,9 @@ TEST(ErrorReporting) {
static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message,
v8::Handle<Value> data) {
CHECK(message->GetScriptResourceName()->IsUndefined());
CHECK_EQ(v8::Undefined(CcTest::isolate()), message->GetScriptResourceName());
CHECK(message->GetScriptOrigin().ResourceName()->IsUndefined());
CHECK_EQ(v8::Undefined(CcTest::isolate()),
message->GetScriptOrigin().ResourceName());
message->GetLineNumber();
message->GetSourceLine();
}
......@@ -8296,9 +8297,9 @@ TEST(ApiUncaughtException) {
static const char* script_resource_name = "ExceptionInNativeScript.js";
static void ExceptionInNativeScriptTestListener(v8::Handle<v8::Message> message,
v8::Handle<Value>) {
v8::Handle<v8::Value> name_val = message->GetScriptResourceName();
v8::Handle<v8::Value> name_val = message->GetScriptOrigin().ResourceName();
CHECK(!name_val.IsEmpty() && name_val->IsString());
v8::String::Utf8Value name(message->GetScriptResourceName());
v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName());
CHECK_EQ(script_resource_name, *name);
CHECK_EQ(3, message->GetLineNumber());
v8::String::Utf8Value source_line(message->GetSourceLine());
......@@ -13028,7 +13029,7 @@ static void WebKitLike(Handle<Message> message, Handle<Value> data) {
Handle<String> errorMessageString = message->Get();
CHECK(!errorMessageString.IsEmpty());
message->GetStackTrace();
message->GetScriptResourceName();
message->GetScriptOrigin().ResourceName();
}
......@@ -14424,7 +14425,7 @@ static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
CHECK_EQ(3, message->GetEndColumn());
v8::String::Utf8Value line(message->GetSourceLine());
CHECK_EQ(" throw 'nirk';", *line);
v8::String::Utf8Value name(message->GetScriptResourceName());
v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName());
CHECK_EQ(resource_name, *name);
}
......@@ -17700,6 +17701,54 @@ TEST(DynamicWithSourceURLInStackTraceString) {
}
TEST(EvalWithSourceURLInMessageScriptResourceNameOrSourceURL) {
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
const char *source =
"function outer() {\n"
" var scriptContents = \"function foo() { FAIL.FAIL; }\\\n"
" //# sourceURL=source_url\";\n"
" eval(scriptContents);\n"
" foo(); }\n"
"outer();\n"
"//# sourceURL=outer_url";
v8::TryCatch try_catch;
CompileRun(source);
CHECK(try_catch.HasCaught());
Local<v8::Message> message = try_catch.Message();
Handle<Value> sourceURL =
message->GetScriptOrigin().ResourceName();
CHECK_EQ(*v8::String::Utf8Value(sourceURL), "source_url");
}
TEST(RecursionWithSourceURLInMessageScriptResourceNameOrSourceURL) {
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
const char *source =
"function outer() {\n"
" var scriptContents = \"function boo(){ boo(); }\\\n"
" //# sourceURL=source_url\";\n"
" eval(scriptContents);\n"
" boo(); }\n"
"outer();\n"
"//# sourceURL=outer_url";
v8::TryCatch try_catch;
CompileRun(source);
CHECK(try_catch.HasCaught());
Local<v8::Message> message = try_catch.Message();
Handle<Value> sourceURL =
message->GetScriptOrigin().ResourceName();
CHECK_EQ(*v8::String::Utf8Value(sourceURL), "source_url");
}
static void CreateGarbageInOldSpace() {
i::Factory* factory = CcTest::i_isolate()->factory();
v8::HandleScope scope(CcTest::isolate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment