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;
var Mirror = global.Mirror;
var MirrorType;
var ParseInt = global.parseInt;
var ToBoolean;
var ValueMirror = global.ValueMirror;
utils.Import(function(from) {
MirrorType = from.MirrorType;
ToBoolean = from.ToBoolean;
});
//----------------------------------------------------------------------------
......@@ -230,7 +228,7 @@ BreakPoint.prototype.isTriggered = function(exec_state) {
try {
var mirror = exec_state.frame(0).evaluate(this.condition());
// 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;
}
} catch (e) {
......@@ -959,7 +957,7 @@ ExecutionState.prototype.prepareStep = function(opt_action, opt_count,
ExecutionState.prototype.evaluateGlobal = function(source, disable_break,
opt_additional_context) {
return MakeMirror(%DebugEvaluateGlobal(this.break_id, source,
ToBoolean(disable_break),
TO_BOOLEAN(disable_break),
opt_additional_context));
};
......@@ -1988,7 +1986,7 @@ DebugCommandProcessor.resolveValue_ = function(value_description) {
return value_mirror.value();
} else if ("stringDescription" in value_description) {
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) {
return TO_NUMBER(value_description.stringDescription);
} if (value_description.type == MirrorType.STRING_TYPE) {
......@@ -2090,7 +2088,7 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) {
if (global) {
// Evaluate in the native context.
response.body = this.exec_state_.evaluateGlobal(
expression, ToBoolean(disable_break), additional_context_object);
expression, TO_BOOLEAN(disable_break), additional_context_object);
return;
}
......@@ -2112,12 +2110,12 @@ DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) {
}
// Evaluate in the specified frame.
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;
} else {
// Evaluate in the selected frame.
response.body = this.exec_state_.frame().evaluate(
expression, ToBoolean(disable_break), additional_context_object);
expression, TO_BOOLEAN(disable_break), additional_context_object);
return;
}
};
......@@ -2138,7 +2136,7 @@ DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) {
// Set 'includeSource' option for script lookup.
if (!IS_UNDEFINED(request.arguments.includeSource)) {
var includeSource = ToBoolean(request.arguments.includeSource);
var includeSource = TO_BOOLEAN(request.arguments.includeSource);
response.setOption('includeSource', includeSource);
}
......@@ -2250,7 +2248,7 @@ DebugCommandProcessor.prototype.scriptsRequest_ = function(request, response) {
}
if (!IS_UNDEFINED(request.arguments.includeSource)) {
includeSource = ToBoolean(request.arguments.includeSource);
includeSource = TO_BOOLEAN(request.arguments.includeSource);
response.setOption('includeSource', includeSource);
}
......
......@@ -16,12 +16,10 @@ var MathMin = global.Math.min;
var promiseStatusSymbol = utils.ImportNow("promise_status_symbol");
var promiseValueSymbol = utils.ImportNow("promise_value_symbol");
var SymbolToString;
var ToBoolean;
utils.Import(function(from) {
FunctionSourceString = from.FunctionSourceString;
SymbolToString = from.SymbolToString;
ToBoolean = from.ToBoolean;
});
// ----------------------------------------------------------------------------
......@@ -2072,7 +2070,7 @@ FrameMirror.prototype.evaluate = function(source, disable_break,
this.details_.frameId(),
this.details_.inlinedFrameIndex(),
source,
ToBoolean(disable_break),
TO_BOOLEAN(disable_break),
opt_context_object));
};
......
......@@ -141,10 +141,11 @@ define kBoundArgumentsStartIndex = 2;
# 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_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_MAP_MINUS_ZERO(arg) = (%_IsSmi(%IS_VAR(arg)) ? arg : %NumberToIntegerMapMinusZero(arg));
macro TO_INT32(arg) = (arg | 0);
macro TO_UINT32(arg) = (arg >>> 0);
macro TO_INT32(arg) = ((arg) | 0);
macro TO_UINT32(arg) = ((arg) >>> 0);
macro TO_LENGTH(arg) = (%ToLength(arg));
macro TO_LENGTH_OR_UINT32(arg) = (harmony_tolength ? TO_LENGTH(arg) : TO_UINT32(arg));
macro TO_STRING(arg) = (%_ToString(arg));
......
......@@ -187,7 +187,6 @@ function PostNatives(utils) {
"OwnPropertyKeys",
"SymbolToString",
"ToNameArray",
"ToBoolean",
// From runtime:
"is_concat_spreadable_symbol",
"iterator_symbol",
......
......@@ -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
function SameValue(x, y) {
if (typeof x != typeof y) return false;
......@@ -222,7 +212,7 @@ function IsConcatSpreadable(O) {
if (!IS_SPEC_OBJECT(O)) return false;
var spreadable = O[isConcatSpreadableSymbol];
if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
return ToBoolean(spreadable);
return TO_BOOLEAN(spreadable);
}
......@@ -260,8 +250,4 @@ $toPositiveInteger = ToPositiveInteger;
"concat_iterable_to_array", ConcatIterableToArray,
]);
utils.Export(function(to) {
to.ToBoolean = ToBoolean;
});
})
......@@ -22,7 +22,6 @@ var ProxyDelegateCallAndConstruct;
var ProxyDerivedHasOwnTrap;
var ProxyDerivedKeysTrap;
var StringIndexOf;
var ToBoolean = utils.ImportNow("ToBoolean");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
......@@ -348,11 +347,11 @@ function ToPropertyDescriptor(obj) {
var desc = new PropertyDescriptor();
if ("enumerable" in obj) {
desc.setEnumerable(ToBoolean(obj.enumerable));
desc.setEnumerable(TO_BOOLEAN(obj.enumerable));
}
if ("configurable" in obj) {
desc.setConfigurable(ToBoolean(obj.configurable));
desc.setConfigurable(TO_BOOLEAN(obj.configurable));
}
if ("value" in obj) {
......@@ -360,7 +359,7 @@ function ToPropertyDescriptor(obj) {
}
if ("writable" in obj) {
desc.setWritable(ToBoolean(obj.writable));
desc.setWritable(TO_BOOLEAN(obj.writable));
}
if ("get" in obj) {
......@@ -614,7 +613,7 @@ function DefineProxyProperty(obj, p, attributes, should_throw) {
var handler = %GetHandler(obj);
var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
if (!ToBoolean(result)) {
if (!result) {
if (should_throw) {
throw MakeTypeError(kProxyHandlerReturned,
handler, "false", "defineProperty");
......@@ -1372,9 +1371,9 @@ function BooleanConstructor(x) {
// TODO(bmeurer): Move this to toplevel.
"use strict";
if (%_IsConstructCall()) {
%_SetValueOf(this, ToBoolean(x));
%_SetValueOf(this, TO_BOOLEAN(x));
} 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