Commit 2963b5bd authored by yangguo's avatar yangguo Committed by Commit bot

[json] check and handle interrupts.

R=jkummerow@chromium.org
BUG=chromium:595626

Review-Url: https://codereview.chromium.org/2037363002
Cr-Commit-Position: refs/heads/master@{#36785}
parent f53d1009
...@@ -249,10 +249,9 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() { ...@@ -249,10 +249,9 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() {
return Handle<Object>::null(); return Handle<Object>::null();
} }
if (stack_check.InterruptRequested()) { if (stack_check.InterruptRequested() &&
ExecutionAccess access(isolate_); isolate_->stack_guard()->HandleInterrupts()->IsException()) {
// Avoid blocking GC in long running parser (v8:3974). return Handle<Object>::null();
isolate_->stack_guard()->HandleGCInterrupt();
} }
if (c0_ == '"') return ParseJsonString(); if (c0_ == '"') return ParseJsonString();
......
...@@ -272,6 +272,11 @@ template <bool deferred_string_key> ...@@ -272,6 +272,11 @@ template <bool deferred_string_key>
JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object, JsonStringifier::Result JsonStringifier::Serialize_(Handle<Object> object,
bool comma, bool comma,
Handle<Object> key) { Handle<Object> key) {
StackLimitCheck interrupt_check(isolate_);
if (interrupt_check.InterruptRequested() &&
isolate_->stack_guard()->HandleInterrupts()->IsException()) {
return EXCEPTION;
}
if (object->IsJSReceiver()) { if (object->IsJSReceiver()) {
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, object, ApplyToJsonFunction(object, key), EXCEPTION); isolate_, object, ApplyToJsonFunction(object, key), EXCEPTION);
...@@ -399,7 +404,12 @@ JsonStringifier::Result JsonStringifier::SerializeJSArray( ...@@ -399,7 +404,12 @@ JsonStringifier::Result JsonStringifier::SerializeJSArray(
case FAST_SMI_ELEMENTS: { case FAST_SMI_ELEMENTS: {
Handle<FixedArray> elements(FixedArray::cast(object->elements()), Handle<FixedArray> elements(FixedArray::cast(object->elements()),
isolate_); isolate_);
StackLimitCheck interrupt_check(isolate_);
while (i < length) { while (i < length) {
if (interrupt_check.InterruptRequested() &&
isolate_->stack_guard()->HandleInterrupts()->IsException()) {
return EXCEPTION;
}
Separator(i == 0); Separator(i == 0);
SerializeSmi(Smi::cast(elements->get(i))); SerializeSmi(Smi::cast(elements->get(i)));
i++; i++;
...@@ -411,7 +421,12 @@ JsonStringifier::Result JsonStringifier::SerializeJSArray( ...@@ -411,7 +421,12 @@ JsonStringifier::Result JsonStringifier::SerializeJSArray(
if (length == 0) break; if (length == 0) break;
Handle<FixedDoubleArray> elements( Handle<FixedDoubleArray> elements(
FixedDoubleArray::cast(object->elements()), isolate_); FixedDoubleArray::cast(object->elements()), isolate_);
StackLimitCheck interrupt_check(isolate_);
while (i < length) { while (i < length) {
if (interrupt_check.InterruptRequested() &&
isolate_->stack_guard()->HandleInterrupts()->IsException()) {
return EXCEPTION;
}
Separator(i == 0); Separator(i == 0);
SerializeDouble(elements->get_scalar(i)); SerializeDouble(elements->get_scalar(i));
i++; i++;
......
...@@ -204,6 +204,31 @@ TEST(TerminateOnlyV8ThreadFromOtherThread) { ...@@ -204,6 +204,31 @@ TEST(TerminateOnlyV8ThreadFromOtherThread) {
semaphore = NULL; semaphore = NULL;
} }
// Test that execution can be terminated from within JSON.stringify.
TEST(TerminateJsonStringify) {
semaphore = new v8::base::Semaphore(0);
TerminatorThread thread(CcTest::i_isolate());
thread.Start();
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::ObjectTemplate> global =
CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
v8::Local<v8::Context> context =
v8::Context::New(CcTest::isolate(), NULL, global);
v8::Context::Scope context_scope(context);
CHECK(!CcTest::isolate()->IsExecutionTerminating());
v8::MaybeLocal<v8::Value> result =
CompileRun(CcTest::isolate()->GetCurrentContext(),
"var x = [];"
"x[2**31]=1;"
"terminate();"
"JSON.stringify(x);"
"fail();");
CHECK(result.IsEmpty());
thread.Join();
delete semaphore;
semaphore = NULL;
}
int call_count = 0; int call_count = 0;
......
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