Commit d59c2cf1 authored by caitp's avatar caitp Committed by Commit bot

[builtins] add CodeStubAssembler::IsDebugActive() helper

Utility used by Promise builtins implemented in TFJ/TFS

BUG=v8:5046
R=bmeurer@chromium.org, gsathya@chromium.org, yangguo@chromium.org, adamk@chromium.org

Review-Url: https://codereview.chromium.org/2517823002
Cr-Commit-Position: refs/heads/master@{#41123}
parent 682f6500
......@@ -7709,5 +7709,12 @@ compiler::Node* CodeStubAssembler::IsHoleyFastElementsKind(
return Word32Equal(holey_elements, Int32Constant(1));
}
compiler::Node* CodeStubAssembler::IsDebugActive() {
Node* is_debug_active = Load(
MachineType::Uint8(),
ExternalConstant(ExternalReference::debug_is_active_address(isolate())));
return WordNotEqual(is_debug_active, Int32Constant(0));
}
} // namespace internal
} // namespace v8
......@@ -1044,6 +1044,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* InstanceOf(compiler::Node* object, compiler::Node* callable,
compiler::Node* context);
// Debug helpers
compiler::Node* IsDebugActive();
// TypedArray/ArrayBuffer helpers
compiler::Node* IsDetachedBuffer(compiler::Node* buffer);
......
......@@ -1760,5 +1760,42 @@ TEST(ArgumentsForEach) {
CHECK_EQ(Smi::FromInt(12 + 13 + 14), *result);
}
TEST(IsDebugActive) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
CodeAssemblerTester data(isolate, kNumParams);
CodeStubAssembler m(data.state());
CodeStubAssembler::Label if_active(&m), if_not_active(&m);
m.Branch(m.IsDebugActive(), &if_active, &if_not_active);
m.Bind(&if_active);
m.Return(m.TrueConstant());
m.Bind(&if_not_active);
m.Return(m.FalseConstant());
Handle<Code> code = data.GenerateCode();
CHECK(!code.is_null());
FunctionTester ft(code, kNumParams);
CHECK_EQ(false, isolate->debug()->is_active());
Handle<Object> result =
ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
CHECK_EQ(isolate->heap()->false_value(), *result);
bool* debug_is_active = reinterpret_cast<bool*>(
ExternalReference::debug_is_active_address(isolate).address());
// Cheat to enable debug (TODO: do this properly).
*debug_is_active = true;
result = ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
CHECK_EQ(isolate->heap()->true_value(), *result);
// Reset debug mode.
*debug_is_active = false;
}
} // namespace internal
} // namespace v8
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