Commit f28e4878 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[console] fast console.assert(true)

A lot of web sites around the world has hack which replaces native console.assert by function with fast return.
Current console.assert is slow because we need to run CPP builtin but we should enter this builtin iff condition is false or omitted.

BUG=v8:6175
R=ishell@chromium.org,dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2828933002
Cr-Commit-Position: refs/heads/master@{#44752}
parent d089276e
......@@ -896,6 +896,7 @@ v8_source_set("v8_builtins_generators") {
"src/builtins/builtins-async-iterator-gen.cc",
"src/builtins/builtins-boolean-gen.cc",
"src/builtins/builtins-call-gen.cc",
"src/builtins/builtins-console-gen.cc",
"src/builtins/builtins-constructor-gen.cc",
"src/builtins/builtins-constructor-gen.h",
"src/builtins/builtins-constructor.h",
......
......@@ -2583,7 +2583,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
false);
SimpleInstallFunction(console, "clear", Builtins::kConsoleClear, 1, false);
SimpleInstallFunction(console, "count", Builtins::kConsoleCount, 1, false);
SimpleInstallFunction(console, "assert", Builtins::kConsoleAssert, 1,
SimpleInstallFunction(console, "assert", Builtins::kFastConsoleAssert, 1,
false);
SimpleInstallFunction(console, "markTimeline",
Builtins::kConsoleMarkTimeline, 1, false);
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h"
namespace v8 {
namespace internal {
TF_BUILTIN(FastConsoleAssert, CodeStubAssembler) {
Label runtime(this);
Label out(this);
// TODO(ishell): use constants from Descriptor once the JSFunction linkage
// arguments are reordered.
Node* argc = Parameter(BuiltinDescriptor::kArgumentsCount);
Node* context = Parameter(BuiltinDescriptor::kContext);
Node* new_target = Parameter(BuiltinDescriptor::kNewTarget);
GotoIf(Word32Equal(argc, Int32Constant(0)), &runtime);
CodeStubArguments args(this, ChangeInt32ToIntPtr(argc));
BranchIfToBooleanIsTrue(args.AtIndex(0), &out, &runtime);
BIND(&out);
args.PopAndReturn(UndefinedConstant());
BIND(&runtime);
{
Node* target = LoadFromFrame(StandardFrameConstants::kFunctionOffset,
MachineType::TaggedPointer());
TailCallBuiltin(Builtins::kConsoleAssert, context, target, new_target,
argc);
}
}
} // namespace internal
} // namespace v8
......@@ -363,6 +363,7 @@ namespace internal {
CPP(ConsoleClear) \
CPP(ConsoleCount) \
CPP(ConsoleAssert) \
TFJ(FastConsoleAssert, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
CPP(ConsoleMarkTimeline) \
CPP(ConsoleProfile) \
CPP(ConsoleProfileEnd) \
......
......@@ -124,6 +124,14 @@ Callable Builtins::CallableFor(Isolate* isolate, Name name) {
}
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, CASE, CASE,
CASE, IGNORE_BUILTIN, IGNORE_BUILTIN)
#undef CASE
#define CASE(Name, ...) \
case k##Name: { \
Handle<Code> code = isolate->builtins()->Name(); \
return Callable(code, BuiltinDescriptor(isolate)); \
}
BUILTIN_LIST(CASE, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN,
IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#undef CASE
default:
UNREACHABLE();
......
......@@ -1094,6 +1094,11 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
return CallStub(Builtins::CallableFor(isolate(), id), context, args...);
}
template <class... TArgs>
Node* TailCallBuiltin(Builtins::Name id, Node* context, TArgs... args) {
return TailCallStub(Builtins::CallableFor(isolate(), id), context, args...);
}
void LoadPropertyFromFastObject(Node* object, Node* map, Node* descriptors,
Node* name_index, Variable* var_details,
Variable* var_value);
......
......@@ -279,7 +279,7 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
ConsoleHelper helper(info, m_inspector);
if (helper.firstArgToBoolean(false)) return;
DCHECK(!helper.firstArgToBoolean(false));
std::vector<v8::Local<v8::Value>> arguments;
for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]);
......
......@@ -487,6 +487,7 @@
'builtins/builtins-call-gen.cc',
'builtins/builtins-callsite.cc',
'builtins/builtins-console.cc',
'builtins/builtins-console-gen.cc',
'builtins/builtins-constructor-gen.cc',
'builtins/builtins-constructor-gen.h',
'builtins/builtins-constructor.h',
......
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