Commit 519f2151 authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Drop useless ToBoolean JavaScript builtin.

There's no need for a dedicated ToBoolean builtin in JavaScript, since
ToBoolean(x) can easily be expressed in JavaScript as !!x, which has the
additional advantage that the compilers are able to properly optimize
that (out of the box).

Review URL: https://codereview.chromium.org/1400463002

Cr-Commit-Position: refs/heads/master@{#31172}
parent fd4e0dc2
...@@ -21,12 +21,10 @@ var MathMin = global.Math.min; ...@@ -21,12 +21,10 @@ var MathMin = global.Math.min;
var Mirror = global.Mirror; var Mirror = global.Mirror;
var MirrorType; var MirrorType;
var ParseInt = global.parseInt; var ParseInt = global.parseInt;
var ToBoolean;
var ValueMirror = global.ValueMirror; var ValueMirror = global.ValueMirror;
utils.Import(function(from) { utils.Import(function(from) {
MirrorType = from.MirrorType; MirrorType = from.MirrorType;
ToBoolean = from.ToBoolean;
}); });
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -230,7 +228,7 @@ BreakPoint.prototype.isTriggered = function(exec_state) { ...@@ -230,7 +228,7 @@ BreakPoint.prototype.isTriggered = function(exec_state) {
try { try {
var mirror = exec_state.frame(0).evaluate(this.condition()); var mirror = exec_state.frame(0).evaluate(this.condition());
// If no sensible mirror or non true value break point not triggered. // If no sensible mirror or non true value break point not triggered.
if (!(mirror instanceof ValueMirror) || !ToBoolean(mirror.value_)) { if (!(mirror instanceof ValueMirror) || !mirror.value_) {
return false; return false;
} }
} catch (e) { } catch (e) {
...@@ -959,7 +957,7 @@ ExecutionState.prototype.prepareStep = function(opt_action, opt_count, ...@@ -959,7 +957,7 @@ ExecutionState.prototype.prepareStep = function(opt_action, opt_count,
ExecutionState.prototype.evaluateGlobal = function(source, disable_break, ExecutionState.prototype.evaluateGlobal = function(source, disable_break,
opt_additional_context) { opt_additional_context) {
return MakeMirror(%DebugEvaluateGlobal(this.break_id, source, return MakeMirror(%DebugEvaluateGlobal(this.break_id, source,
ToBoolean(disable_break), TO_BOOLEAN(disable_break),
opt_additional_context)); opt_additional_context));
}; };
...@@ -1988,7 +1986,7 @@ DebugCommandProcessor.resolveValue_ = function(value_description) { ...@@ -1988,7 +1986,7 @@ DebugCommandProcessor.resolveValue_ = function(value_description) {
return value_mirror.value(); return value_mirror.value();
} else if ("stringDescription" in value_description) { } else if ("stringDescription" in value_description) {
if (value_description.type == MirrorType.BOOLEAN_TYPE) { if (value_description.type == MirrorType.BOOLEAN_TYPE) {
return ToBoolean(value_description.stringDescription); return TO_BOOLEAN(value_description.stringDescription);
} else if (value_description.type == MirrorType.NUMBER_TYPE) { } else if (value_description.type == MirrorType.NUMBER_TYPE) {
return TO_NUMBER(value_description.stringDescription); return TO_NUMBER(value_description.stringDescription);
} if (value_description.type == MirrorType.STRING_TYPE) { } if (value_description.type == MirrorType.STRING_TYPE) {
...@@ -2090,7 +2088,7 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { ...@@ -2090,7 +2088,7 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) {
if (global) { if (global) {
// Evaluate in the native context. // Evaluate in the native context.
response.body = this.exec_state_.evaluateGlobal( response.body = this.exec_state_.evaluateGlobal(
expression, ToBoolean(disable_break), additional_context_object); expression, TO_BOOLEAN(disable_break), additional_context_object);
return; return;
} }
...@@ -2112,12 +2110,12 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { ...@@ -2112,12 +2110,12 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) {
} }
// Evaluate in the specified frame. // Evaluate in the specified frame.
response.body = this.exec_state_.frame(frame_number).evaluate( response.body = this.exec_state_.frame(frame_number).evaluate(
expression, ToBoolean(disable_break), additional_context_object); expression, TO_BOOLEAN(disable_break), additional_context_object);
return; return;
} else { } else {
// Evaluate in the selected frame. // Evaluate in the selected frame.
response.body = this.exec_state_.frame().evaluate( response.body = this.exec_state_.frame().evaluate(
expression, ToBoolean(disable_break), additional_context_object); expression, TO_BOOLEAN(disable_break), additional_context_object);
return; return;
} }
}; };
...@@ -2138,7 +2136,7 @@ DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { ...@@ -2138,7 +2136,7 @@ DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) {
// Set 'includeSource' option for script lookup. // Set 'includeSource' option for script lookup.
if (!IS_UNDEFINED(request.arguments.includeSource)) { if (!IS_UNDEFINED(request.arguments.includeSource)) {
var includeSource = ToBoolean(request.arguments.includeSource); var includeSource = TO_BOOLEAN(request.arguments.includeSource);
response.setOption('includeSource', includeSource); response.setOption('includeSource', includeSource);
} }
...@@ -2250,7 +2248,7 @@ DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) { ...@@ -2250,7 +2248,7 @@ DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) {
} }
if (!IS_UNDEFINED(request.arguments.includeSource)) { if (!IS_UNDEFINED(request.arguments.includeSource)) {
includeSource = ToBoolean(request.arguments.includeSource); includeSource = TO_BOOLEAN(request.arguments.includeSource);
response.setOption('includeSource', includeSource); response.setOption('includeSource', includeSource);
} }
......
...@@ -16,12 +16,10 @@ var MathMin = global.Math.min; ...@@ -16,12 +16,10 @@ var MathMin = global.Math.min;
var promiseStatusSymbol = utils.ImportNow("promise_status_symbol"); var promiseStatusSymbol = utils.ImportNow("promise_status_symbol");
var promiseValueSymbol = utils.ImportNow("promise_value_symbol"); var promiseValueSymbol = utils.ImportNow("promise_value_symbol");
var SymbolToString; var SymbolToString;
var ToBoolean;
utils.Import(function(from) { utils.Import(function(from) {
FunctionSourceString = from.FunctionSourceString; FunctionSourceString = from.FunctionSourceString;
SymbolToString = from.SymbolToString; SymbolToString = from.SymbolToString;
ToBoolean = from.ToBoolean;
}); });
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -2072,7 +2070,7 @@ FrameMirror.prototype.evaluate = function(source, disable_break, ...@@ -2072,7 +2070,7 @@ FrameMirror.prototype.evaluate = function(source, disable_break,
this.details_.frameId(), this.details_.frameId(),
this.details_.inlinedFrameIndex(), this.details_.inlinedFrameIndex(),
source, source,
ToBoolean(disable_break), TO_BOOLEAN(disable_break),
opt_context_object)); opt_context_object));
}; };
......
...@@ -141,10 +141,11 @@ define kBoundArgumentsStartIndex = 2; ...@@ -141,10 +141,11 @@ define kBoundArgumentsStartIndex = 2;
# Inline macros. Use %IS_VAR to make sure arg is evaluated only once. # Inline macros. Use %IS_VAR to make sure arg is evaluated only once.
macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg)); macro NUMBER_IS_NAN(arg) = (!%_IsSmi(%IS_VAR(arg)) && !(arg == arg));
macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0))); macro NUMBER_IS_FINITE(arg) = (%_IsSmi(%IS_VAR(arg)) || ((arg == arg) && (arg != 1/0) && (arg != -1/0)));
macro TO_BOOLEAN(arg) = (!!(arg));
macro TO_INTEGER(arg) = (%_ToInteger(arg)); macro TO_INTEGER(arg) = (%_ToInteger(arg));
macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(arg)); macro TO_INTEGER_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(arg));
macro TO_INT32(arg) = (arg | 0); macro TO_INT32(arg) = ((arg) | 0);
macro TO_UINT32(arg) = (arg >>> 0); macro TO_UINT32(arg) = ((arg) >>> 0);
macro TO_LENGTH(arg) = (%ToLength(arg)); macro TO_LENGTH(arg) = (%ToLength(arg));
macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg)); macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg));
macro TO_STRING(arg) = (%_ToString(arg)); macro TO_STRING(arg) = (%_ToString(arg));
......
...@@ -187,7 +187,6 @@ function PostNatives(utils) { ...@@ -187,7 +187,6 @@ function PostNatives(utils) {
"OwnPropertyKeys", "OwnPropertyKeys",
"SymbolToString", "SymbolToString",
"ToNameArray", "ToNameArray",
"ToBoolean",
// From runtime: // From runtime:
"is_concat_spreadable_symbol", "is_concat_spreadable_symbol",
"iterator_symbol", "iterator_symbol",
......
...@@ -166,16 +166,6 @@ function CONCAT_ITERABLE_TO_ARRAY(iterable) { ...@@ -166,16 +166,6 @@ function CONCAT_ITERABLE_TO_ARRAY(iterable) {
------------------------------------- -------------------------------------
*/ */
// ECMA-262, section 9.2, page 30
function ToBoolean(x) {
if (IS_BOOLEAN(x)) return x;
if (IS_STRING(x)) return x.length != 0;
if (x == null) return false;
if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
return true;
}
// ES5, section 9.12 // ES5, section 9.12
function SameValue(x, y) { function SameValue(x, y) {
if (typeof x != typeof y) return false; if (typeof x != typeof y) return false;
...@@ -222,7 +212,7 @@ function IsConcatSpreadable(O) { ...@@ -222,7 +212,7 @@ function IsConcatSpreadable(O) {
if (!IS_SPEC_OBJECT(O)) return false; if (!IS_SPEC_OBJECT(O)) return false;
var spreadable = O[isConcatSpreadableSymbol]; var spreadable = O[isConcatSpreadableSymbol];
if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
return ToBoolean(spreadable); return TO_BOOLEAN(spreadable);
} }
...@@ -260,8 +250,4 @@ $toPositiveInteger = ToPositiveInteger; ...@@ -260,8 +250,4 @@ $toPositiveInteger = ToPositiveInteger;
"concat_iterable_to_array", ConcatIterableToArray, "concat_iterable_to_array", ConcatIterableToArray,
]); ]);
utils.Export(function(to) {
to.ToBoolean = ToBoolean;
});
}) })
...@@ -22,7 +22,6 @@ var ProxyDelegateCallAndConstruct; ...@@ -22,7 +22,6 @@ var ProxyDelegateCallAndConstruct;
var ProxyDerivedHasOwnTrap; var ProxyDerivedHasOwnTrap;
var ProxyDerivedKeysTrap; var ProxyDerivedKeysTrap;
var StringIndexOf; var StringIndexOf;
var ToBoolean = utils.ImportNow("ToBoolean");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) { utils.Import(function(from) {
...@@ -348,11 +347,11 @@ function ToPropertyDescriptor(obj) { ...@@ -348,11 +347,11 @@ function ToPropertyDescriptor(obj) {
var desc = new PropertyDescriptor(); var desc = new PropertyDescriptor();
if ("enumerable" in obj) { if ("enumerable" in obj) {
desc.setEnumerable(ToBoolean(obj.enumerable)); desc.setEnumerable(TO_BOOLEAN(obj.enumerable));
} }
if ("configurable" in obj) { if ("configurable" in obj) {
desc.setConfigurable(ToBoolean(obj.configurable)); desc.setConfigurable(TO_BOOLEAN(obj.configurable));
} }
if ("value" in obj) { if ("value" in obj) {
...@@ -360,7 +359,7 @@ function ToPropertyDescriptor(obj) { ...@@ -360,7 +359,7 @@ function ToPropertyDescriptor(obj) {
} }
if ("writable" in obj) { if ("writable" in obj) {
desc.setWritable(ToBoolean(obj.writable)); desc.setWritable(TO_BOOLEAN(obj.writable));
} }
if ("get" in obj) { if ("get" in obj) {
...@@ -614,7 +613,7 @@ function DefineProxyProperty(obj, p, attributes, should_throw) { ...@@ -614,7 +613,7 @@ function DefineProxyProperty(obj, p, attributes, should_throw) {
var handler = %GetHandler(obj); var handler = %GetHandler(obj);
var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
if (!ToBoolean(result)) { if (!result) {
if (should_throw) { if (should_throw) {
throw MakeTypeError(kProxyHandlerReturned, throw MakeTypeError(kProxyHandlerReturned,
handler, "false", "defineProperty"); handler, "false", "defineProperty");
...@@ -1372,9 +1371,9 @@ function BooleanConstructor(x) { ...@@ -1372,9 +1371,9 @@ function BooleanConstructor(x) {
// TODO(bmeurer): Move this to toplevel. // TODO(bmeurer): Move this to toplevel.
"use strict"; "use strict";
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
%_SetValueOf(this, ToBoolean(x)); %_SetValueOf(this, TO_BOOLEAN(x));
} else { } else {
return ToBoolean(x); return TO_BOOLEAN(x);
} }
} }
......
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