Reviewers: vsevik,
https://codereview.chromium.org/265593002/diff/40001/test/cctest/test-api.cc
File test/cctest/test-api.cc (right):
https://codereview.chromium.org/265593002/diff/40001/test/cctest/test-api.cc#newcode17691
test/cctest/test-api.cc:17691: "//# sourceURL=foo2.js\";\n"
On 2014/04/30 10:18:40, vsevik wrote:
could you please break this string (e.g.
"//# source"
"URL=foo2.js\";\n"
To make sure we don't have any possible false sourceURL matches.
Done.
https://codereview.chromium.org/265593002/diff/40001/test/cctest/test-api.cc#newcode17719
test/cctest/test-api.cc:17719: v8::String::Utf8Value
stack(try_catch.StackTrace());
On 2014/04/30 10:18:40, vsevik wrote:
ditto
Done.
Description:
Add GetScriptResourceNameOrSourceURL with tests
There is one Message::GetScriptResourceNameOrSourceURL() function: returns
the
resource name or sourceURL (from //# sourceURL=) for the script from where
the
function causing the error originates.
Function used in Blink: https://codereview.chromium.org/260513004/
Please review this at https://codereview.chromium.org/265593002/
SVN Base: git://github.com/v8/v8.git@master
Affected files (+70, -0 lines):
M include/v8.h
M src/api.cc
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
684b2c292ed9448a739e46b8358bb0339eb69d43..53389599bf8322f552ee108f3d2bfd90c1e69e83
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1131,6 +1131,12 @@ class V8_EXPORT Message {
Handle<Value> GetScriptResourceName() const;
/**
+ * Returns the resource name or sourceURL for the script from where the
+ * function causing the error originates.
+ */
+ Handle<Value> GetScriptResourceNameOrSourceURL() const;
+
+ /**
* Returns the resource data for the script from where the function
causing
* the error originates.
*/
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
ab4ded2472971ea519ba412b40c16bfc39804ad1..1e043bf3c5cf452ec21633c4549ec79768a8130a
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1937,6 +1937,22 @@ v8::Handle<Value> Message::GetScriptResourceName()
const {
}
+v8::Handle<Value> Message::GetScriptResourceNameOrSourceURL() 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));
+
+ i::Handle<i::JSValue> scriptValue =
+ i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(),
+ isolate));
+ i::Handle<i::Script> script(i::Script::cast(scriptValue->value()));
+ i::Handle<i::Object> script_name = i::Script::GetNameOrSourceURL(script);
+ return scope.Escape(Utils::ToLocal(script_name));
+}
+
+
v8::Handle<v8::StackTrace> Message::GetStackTrace() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
5f82bd7f2e7ee184975588e4de3e6b7fcebbe325..9e9a2f47be680a8aeee7645efd804cf5935f4b46
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -17681,6 +17681,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"
+ " //# source"
+ "URL=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->GetScriptResourceNameOrSourceURL();
+ 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"
+ " //# source"
+ "URL=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->GetScriptResourceNameOrSourceURL();
+ CHECK_EQ(*v8::String::Utf8Value(sourceURL), "source_url");
+}
+
+
static void CreateGarbageInOldSpace() {
i::Factory* factory = CcTest::i_isolate()->factory();
v8::HandleScope scope(CcTest::isolate());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.