99e13e587e
This CL adds a new "Call" stub that can be used by builtins that will call the same JS call-back function often (e.g. compare function in Array.p.sort). The checks have to be done upfront once, but can then be omitted. R=jgruber@chromium.org Bug: v8:7861 Change-Id: Id6e4ca27c3d488a7b1f708cbcb4cbe6cc382513e Reviewed-on: https://chromium-review.googlesource.com/1208574 Commit-Queue: Simon Zünd <szuend@google.com> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#55769}
45 lines
994 B
JavaScript
45 lines
994 B
JavaScript
// Copyright 2018 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.
|
|
|
|
// Exercises the check that determines whether to use the
|
|
// "FastCallFunction_" stub when calling the comparison function.
|
|
|
|
(function TestClassConstructorAsCmpFn() {
|
|
class FooBar {};
|
|
assertThrows(() => [1, 2].sort(FooBar));
|
|
})();
|
|
|
|
|
|
const globalThis = this;
|
|
(function TestGlobalProxyIsSetAsReceiverWhenSloppy() {
|
|
[1, 2].sort((a, b) => {
|
|
assertSame(globalThis, this);
|
|
return a - b;
|
|
});
|
|
})();
|
|
|
|
|
|
(function TestReceiverIsUndefinedWhenStrict() {
|
|
"use strict";
|
|
|
|
[1, 2].sort((a, b) => {
|
|
assertSame(undefined, this);
|
|
return a - b;
|
|
});
|
|
})();
|
|
|
|
|
|
(function TestBoundFunctionAsCmpFn() {
|
|
const object = { foo: "bar" };
|
|
|
|
function cmpfn(a, b) {
|
|
assertSame(this, object);
|
|
assertSame(this.foo, "bar");
|
|
return a - b;
|
|
};
|
|
|
|
const bound_cmpfn = cmpfn.bind(object);
|
|
[1, 2].sort(bound_cmpfn);
|
|
})();
|