Commit 5f9c0df4 authored by verwaest's avatar verwaest Committed by Commit bot

Remove GetDefaultReceiver, pass in undefined to sloppy-mode functions instead.

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

Cr-Commit-Position: refs/heads/master@{#28255}
parent 8ceb9035
......@@ -872,14 +872,12 @@ function ArraySort(comparefn) {
else return x < y ? -1 : 1;
};
}
var receiver = %GetDefaultReceiver(comparefn);
var InsertionSort = function InsertionSort(a, from, to) {
for (var i = from + 1; i < to; i++) {
var element = a[i];
for (var j = i - 1; j >= from; j--) {
var tmp = a[j];
var order = %_CallFunction(receiver, tmp, element, comparefn);
var order = %_CallFunction(UNDEFINED, tmp, element, comparefn);
if (order > 0) {
a[j + 1] = tmp;
} else {
......@@ -898,7 +896,7 @@ function ArraySort(comparefn) {
t_array[j] = [i, a[i]];
}
%_CallFunction(t_array, function(a, b) {
return %_CallFunction(receiver, a[1], b[1], comparefn);
return %_CallFunction(UNDEFINED, a[1], b[1], comparefn);
}, ArraySort);
var third_index = t_array[t_array.length >> 1][0];
return third_index;
......@@ -921,14 +919,14 @@ function ArraySort(comparefn) {
var v0 = a[from];
var v1 = a[to - 1];
var v2 = a[third_index];
var c01 = %_CallFunction(receiver, v0, v1, comparefn);
var c01 = %_CallFunction(UNDEFINED, v0, v1, comparefn);
if (c01 > 0) {
// v1 < v0, so swap them.
var tmp = v0;
v0 = v1;
v1 = tmp;
} // v0 <= v1.
var c02 = %_CallFunction(receiver, v0, v2, comparefn);
var c02 = %_CallFunction(UNDEFINED, v0, v2, comparefn);
if (c02 >= 0) {
// v2 <= v0 <= v1.
var tmp = v0;
......@@ -937,7 +935,7 @@ function ArraySort(comparefn) {
v1 = tmp;
} else {
// v0 <= v1 && v0 < v2
var c12 = %_CallFunction(receiver, v1, v2, comparefn);
var c12 = %_CallFunction(UNDEFINED, v1, v2, comparefn);
if (c12 > 0) {
// v0 <= v2 < v1
var tmp = v1;
......@@ -958,7 +956,7 @@ function ArraySort(comparefn) {
// From i to high_start are elements that haven't been compared yet.
partition: for (var i = low_end + 1; i < high_start; i++) {
var element = a[i];
var order = %_CallFunction(receiver, element, pivot, comparefn);
var order = %_CallFunction(UNDEFINED, element, pivot, comparefn);
if (order < 0) {
a[i] = a[low_end];
a[low_end] = element;
......@@ -968,7 +966,7 @@ function ArraySort(comparefn) {
high_start--;
if (high_start == i) break partition;
var top_elem = a[high_start];
order = %_CallFunction(receiver, top_elem, pivot, comparefn);
order = %_CallFunction(UNDEFINED, top_elem, pivot, comparefn);
} while (order > 0);
a[i] = a[high_start];
a[high_start] = element;
......@@ -1155,9 +1153,9 @@ function ArrayFilter(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -1192,9 +1190,9 @@ function ArrayForEach(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -1224,9 +1222,9 @@ function ArraySome(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -1255,9 +1253,9 @@ function ArrayEvery(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -1286,9 +1284,9 @@ function ArrayMap(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -1444,14 +1442,13 @@ function ArrayReduce(callback, current) {
throw MakeTypeError(kReduceNoInitial);
}
var receiver = %GetDefaultReceiver(callback);
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
for (; i < length; i++) {
if (HAS_INDEX(array, i, is_array)) {
var element = array[i];
// Prepare break slots for debugger step in.
if (stepping) %DebugPrepareStepInIfStepping(callback);
current = %_CallFunction(receiver, current, element, i, array, callback);
current = %_CallFunction(UNDEFINED, current, element, i, array, callback);
}
}
return current;
......@@ -1482,14 +1479,13 @@ function ArrayReduceRight(callback, current) {
throw MakeTypeError(kReduceNoInitial);
}
var receiver = %GetDefaultReceiver(callback);
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
for (; i >= 0; i--) {
if (HAS_INDEX(array, i, is_array)) {
var element = array[i];
// Prepare break slots for debugger step in.
if (stepping) %DebugPrepareStepInIfStepping(callback);
current = %_CallFunction(receiver, current, element, i, array, callback);
current = %_CallFunction(UNDEFINED, current, element, i, array, callback);
}
}
return current;
......
......@@ -209,9 +209,9 @@ function SetForEach(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......@@ -399,9 +399,9 @@ function MapForEach(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......
......@@ -83,9 +83,9 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(thisArg)) {
thisArg = %GetDefaultReceiver(predicate) || thisArg;
} else {
if (IS_NULL(thisArg)) {
if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
} else if (!IS_UNDEFINED(thisArg)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
}
......@@ -120,9 +120,9 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(thisArg)) {
thisArg = %GetDefaultReceiver(predicate) || thisArg;
} else {
if (IS_NULL(thisArg)) {
if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED;
} else if (!IS_UNDEFINED(thisArg)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(predicate, thisArg);
}
......@@ -190,10 +190,12 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
if (mapping) {
if (!IS_SPEC_FUNCTION(mapfn)) {
throw MakeTypeError(kCalledNonCallable, mapfn);
} else if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(mapfn) || receiver;
} else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) {
receiver = ToObject(receiver);
} else if (%IsSloppyModeFunction(mapfn)) {
if (IS_NULL(receiver)) {
receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
receiver = TO_OBJECT_INLINE(receiver);
}
}
}
......
......@@ -44,9 +44,9 @@ function NAMEForEach(f /* thisArg */) { // length == 1
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
} else {
if (IS_NULL(receiver)) {
if (%IsSloppyModeFunction(mapfn)) receiver = UNDEFINED;
} else if (!IS_UNDEFINED(receiver)) {
needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
}
......
......@@ -33,32 +33,6 @@ RUNTIME_FUNCTION(Runtime_IsSloppyModeFunction) {
}
RUNTIME_FUNCTION(Runtime_GetDefaultReceiver) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSReceiver, callable, 0);
if (!callable->IsJSFunction()) {
HandleScope scope(isolate);
Handle<Object> delegate;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, delegate, Execution::TryGetFunctionDelegate(
isolate, Handle<JSReceiver>(callable)));
callable = JSFunction::cast(*delegate);
}
JSFunction* function = JSFunction::cast(callable);
SharedFunctionInfo* shared = function->shared();
if (shared->native() || is_strict(shared->language_mode())) {
return isolate->heap()->undefined_value();
}
// Returns undefined for strict or native functions, or
// the associated global receiver for "normal" functions.
return function->global_proxy();
}
RUNTIME_FUNCTION(Runtime_FunctionGetName) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
......
......@@ -189,7 +189,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_FUNCTION(F) \
F(IsSloppyModeFunction, 1, 1) \
F(GetDefaultReceiver, 1, 1) \
F(FunctionGetName, 1, 1) \
F(FunctionSetName, 2, 1) \
F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
......
......@@ -291,7 +291,7 @@ function StringReplace(search, replace) {
// Compute the string to replace with.
if (IS_SPEC_FUNCTION(replace)) {
var receiver = %GetDefaultReceiver(replace);
var receiver = UNDEFINED;
result += %_CallFunction(receiver, search, start, subject, replace);
} else {
reusableMatchInfo[CAPTURE0] = start;
......@@ -440,7 +440,6 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) {
// function.
var match_start = 0;
var override = new InternalPackedArray(null, 0, subject);
var receiver = %GetDefaultReceiver(replace);
for (var i = 0; i < len; i++) {
var elem = res[i];
if (%_IsSmi(elem)) {
......@@ -457,7 +456,7 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) {
override[1] = match_start;
$regexpLastMatchInfoOverride = override;
var func_result =
%_CallFunction(receiver, elem, match_start, subject, replace);
%_CallFunction(UNDEFINED, elem, match_start, subject, replace);
// Overwrite the i'th element in the results with the string we got
// back from the callback function.
res[i] = TO_STRING_INLINE(func_result);
......@@ -465,14 +464,13 @@ function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) {
}
}
} else {
var receiver = %GetDefaultReceiver(replace);
for (var i = 0; i < len; i++) {
var elem = res[i];
if (!%_IsSmi(elem)) {
// elem must be an Array.
// Use the apply argument as backing for global RegExp properties.
$regexpLastMatchInfoOverride = elem;
var func_result = %Apply(replace, receiver, elem, 0, elem.length);
var func_result = %Apply(replace, UNDEFINED, elem, 0, elem.length);
// Overwrite the i'th element in the results with the string we got
// back from the callback function.
res[i] = TO_STRING_INLINE(func_result);
......@@ -500,12 +498,11 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) {
// The number of captures plus one for the match.
var m = NUMBER_OF_CAPTURES(matchInfo) >> 1;
var replacement;
var receiver = %GetDefaultReceiver(replace);
if (m == 1) {
// No captures, only the match, which is always valid.
var s = %_SubString(subject, index, endOfMatch);
// Don't call directly to avoid exposing the built-in global object.
replacement = %_CallFunction(receiver, s, index, subject, replace);
replacement = %_CallFunction(UNDEFINED, s, index, subject, replace);
} else {
var parameters = new InternalArray(m + 2);
for (var j = 0; j < m; j++) {
......@@ -514,7 +511,7 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) {
parameters[j] = index;
parameters[j + 1] = subject;
replacement = %Apply(replace, receiver, parameters, 0, j + 2);
replacement = %Apply(replace, UNDEFINED, parameters, 0, j + 2);
}
result += replacement; // The add method converts to string if necessary.
......
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