Commit 02503b08 authored by yangguo's avatar yangguo Committed by Commit bot

Make stack property collected by captureStackTrace non-enumerable and -writable.

TBR=jgruber@chromium.org

Review-Url: https://codereview.chromium.org/2177183002
Cr-Commit-Position: refs/heads/master@{#38005}
parent fe728e52
...@@ -50,11 +50,15 @@ BUILTIN(ErrorCaptureStackTrace) { ...@@ -50,11 +50,15 @@ BUILTIN(ErrorCaptureStackTrace) {
isolate, formatted_stack_trace, isolate, formatted_stack_trace,
FormatStackTrace(isolate, object, stack_trace)); FormatStackTrace(isolate, object, stack_trace));
RETURN_FAILURE_ON_EXCEPTION( PropertyDescriptor desc;
isolate, JSObject::SetProperty(object, isolate->factory()->stack_string(), desc.set_configurable(true);
formatted_stack_trace, STRICT)); desc.set_value(formatted_stack_trace);
Maybe<bool> status = JSReceiver::DefineOwnProperty(
return *isolate->factory()->undefined_value(); isolate, object, isolate->factory()->stack_string(), &desc,
Object::THROW_ON_ERROR);
if (!status.IsJust()) return isolate->heap()->exception();
CHECK(status.FromJust());
return isolate->heap()->undefined_value();
} }
namespace { namespace {
......
...@@ -381,6 +381,15 @@ assertEquals(undefined, error.stack); ...@@ -381,6 +381,15 @@ assertEquals(undefined, error.stack);
error = new Error(); error = new Error();
Error.captureStackTrace(error); Error.captureStackTrace(error);
// Check property descriptor.
var o = {};
Error.captureStackTrace(o);
assertEquals([], Object.keys(o));
var desc = Object.getOwnPropertyDescriptor(o, "stack");
assertFalse(desc.writable);
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
// Check that exceptions thrown within prepareStackTrace throws an exception. // Check that exceptions thrown within prepareStackTrace throws an exception.
Error.prepareStackTrace = function(e, frames) { throw 42; } Error.prepareStackTrace = function(e, frames) { throw 42; }
......
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