Reviewers: marja,
Description:
Stack traces exposed to Javascript should omit extensions.
[email protected]
BUG=v8:311
LOG=Y
Please review this at https://codereview.chromium.org/363893003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+50, -10 lines):
M src/debug.cc
M src/isolate.cc
M src/objects.h
M src/objects-inl.h
M test/cctest/test-api.cc
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index
b19b47e4fa26df3cab0f2ab6901b42f3d7c0f654..8eec14ae06adf988f59f8b3e8b8de37c6783ce8c
100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -1226,7 +1226,7 @@ void
Debug::FloodBoundFunctionWithOneShot(Handle<JSFunction> function) {
isolate_);
if (!bindee.is_null() && bindee->IsJSFunction() &&
- !JSFunction::cast(*bindee)->IsNative()) {
+ !JSFunction::cast(*bindee)->IsFromNativeScript()) {
Handle<JSFunction> bindee_function(JSFunction::cast(*bindee));
Debug::FloodWithOneShot(bindee_function);
}
@@ -1447,7 +1447,8 @@ void Debug::PrepareStep(StepAction step_action,
frames_it.Advance();
}
// Skip builtin functions on the stack.
- while (!frames_it.done() && frames_it.frame()->function()->IsNative())
{
+ while (!frames_it.done() &&
+ frames_it.frame()->function()->IsFromNativeScript()) {
frames_it.Advance();
}
// Step out: If there is a JavaScript caller frame, we need to
@@ -1534,7 +1535,7 @@ void Debug::PrepareStep(StepAction step_action,
Handle<JSFunction> js_function(JSFunction::cast(fun));
if (js_function->shared()->bound()) {
Debug::FloodBoundFunctionWithOneShot(js_function);
- } else if (!js_function->IsNative()) {
+ } else if (!js_function->IsFromNativeScript()) {
// Don't step into builtins.
// It will also compile target function if it's not compiled yet.
FloodWithOneShot(js_function);
@@ -1676,7 +1677,7 @@ void Debug::HandleStepIn(Handle<JSFunction> function,
if (function->shared()->bound()) {
// Handle Function.prototype.bind
Debug::FloodBoundFunctionWithOneShot(function);
- } else if (!function->IsNative()) {
+ } else if (!function->IsFromNativeScript()) {
// Don't allow step into functions in the native context.
if (function->shared()->code() ==
isolate->builtins()->builtin(Builtins::kFunctionApply) ||
@@ -1688,7 +1689,7 @@ void Debug::HandleStepIn(Handle<JSFunction> function,
// function.
if (!holder.is_null() && holder->IsJSFunction()) {
Handle<JSFunction> js_function =
Handle<JSFunction>::cast(holder);
- if (!js_function->IsNative()) {
+ if (!js_function->IsFromNativeScript()) {
Debug::FloodWithOneShot(js_function);
} else if (js_function->shared()->bound()) {
// Handle Function.prototype.bind
@@ -2030,7 +2031,7 @@ void Debug::PrepareForBreakPoints() {
if (!shared->allows_lazy_compilation()) continue;
if (!shared->script()->IsScript()) continue;
- if (function->IsNative()) continue;
+ if (function->IsFromNativeScript()) continue;
if (shared->code()->gc_metadata() == active_code_marker)
continue;
if (shared->is_generator()) {
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index
647b9a4b2453d3a1d95cfff287f2e18794630336..dff816ba01d6acaaa427c5a71c6b75d847e1cf8b
100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -344,8 +344,10 @@ static bool IsVisibleInStackTrace(StackFrame*
raw_frame,
// The --builtins-in-stack-traces command line flag allows including
// internal call sites in the stack trace for debugging purposes.
if (!FLAG_builtins_in_stack_traces) {
- if (frame->receiver()->IsJSBuiltinsObject() ||
- (fun->IsBuiltin() && !fun->shared()->native())) {
+ if (frame->receiver()->IsJSBuiltinsObject()) return false;
+ if (fun->IsBuiltin()) {
+ return fun->shared()->native();
+ } else if (fun->IsFromNativeScript() || fun->IsFromExtensionScript()) {
return false;
}
}
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
50c9f3c28d49f40ff5236cfe93c2dd4db21fe800..95b257229972cf9bbb177f649bc6b56654549f81
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -5657,7 +5657,7 @@ bool JSFunction::IsBuiltin() {
}
-bool JSFunction::IsNative() {
+bool JSFunction::IsFromNativeScript() {
Object* script = shared()->script();
bool native = script->IsScript() &&
Script::cast(script)->type()->value() ==
Script::TYPE_NATIVE;
@@ -5666,6 +5666,13 @@ bool JSFunction::IsNative() {
}
+bool JSFunction::IsFromExtensionScript() {
+ Object* script = shared()->script();
+ return script->IsScript() &&
+ Script::cast(script)->type()->value() == Script::TYPE_EXTENSION;
+}
+
+
bool JSFunction::NeedsArgumentsAdaption() {
return shared()->formal_parameter_count() !=
SharedFunctionInfo::kDontAdaptArgumentsSentinel;
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
74aaedf58ba55a599e11704f9eecd339cb2ec76a..3e83eda46f82b11c190041a7e29b0dd6d12272e9
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -7634,7 +7634,10 @@ class JSFunction: public JSObject {
inline bool IsBuiltin();
// Tells whether this function is defined in a native script.
- inline bool IsNative();
+ inline bool IsFromNativeScript();
+
+ // Tells whether this function is defined in an extension script.
+ inline bool IsFromExtensionScript();
// Tells whether or not the function needs arguments adaption.
inline bool NeedsArgumentsAdaption();
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
14174259cf6382cf95f1c00e792547064cfb1f6c..04085961492ded446bc2326a65f72e3d1696ac06
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -6694,6 +6694,33 @@ TEST(SimpleExtensions) {
}
+static const char* kStackTraceFromExtensionSource =
+ "function foo() {"
+ " throw new Error();"
+ "}"
+ "function bar() {"
+ " foo();"
+ "}";
+
+
+TEST(StackTraceInExtension) {
+ v8::HandleScope handle_scope(CcTest::isolate());
+ v8::RegisterExtension(new Extension("stacktracetest",
+ kStackTraceFromExtensionSource));
+ const char* extension_names[] = { "stacktracetest" };
+ v8::ExtensionConfiguration extensions(1, extension_names);
+ v8::Handle<Context> context =
+ Context::New(CcTest::isolate(), &extensions);
+ Context::Scope lock(context);
+ CompileRun("function user() { bar(); }"
+ "var error;"
+ "try{ user(); } catch (e) { error = e; }");
+ CHECK_EQ(-1, CompileRun("error.stack.indexOf('foo')")->Int32Value());
+ CHECK_EQ(-1, CompileRun("error.stack.indexOf('bar')")->Int32Value());
+ CHECK_NE(-1, CompileRun("error.stack.indexOf('user')")->Int32Value());
+}
+
+
TEST(NullExtensions) {
v8::HandleScope handle_scope(CcTest::isolate());
v8::RegisterExtension(new Extension("nulltest", NULL));
--
--
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.