v8/test/mjsunit/compiler/reflect-has.js
Benedikt Meurer 4213af64b6 [es2015] Optimize Reflect.has builtin.
Port the baseline version of Reflect.has to the CodeStubAssembler and
reuse the existing logic for HasProperty (i.e. the HasProperty builtin).
Also inline the Reflect.has builtin into TurboFan, by adding a check
on the target in front of a use of the JSHasProperty operator.
Technically this additional check is not necessary, because the
JSHasProperty operator already throws if the target is not a JSReceiver,
but the exception message is confusing then.

This improves the performance of the micro-benchmark from

  reflectHasPresent: 337 ms.
  reflectHasAbsent: 472 ms.

to

  reflectHasPresent: 121 ms.
  reflectHasAbsent: 216 ms.

which is a nice 2.8x improvement in the best case. It also improves the
chai test on the web-tooling-benchmark by around 1-2%, which is roughly
the expected win (since Reflect.has overall accounts for around 3-4%).

Bug: v8:5996, v8:6936, v8:6937
Change-Id: I856183229677a71c19936f06f2a4fc7a794a9a4a
Reviewed-on: https://chromium-review.googlesource.com/720959
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48608}
2017-10-16 17:27:41 +00:00

68 lines
1.5 KiB
JavaScript

// 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.
// Flags: --allow-natives-syntax
// Test Reflect.has with wrong (number of) arguments.
(function() {
"use strict";
function foo() { return Reflect.has(); }
assertThrows(foo);
assertThrows(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(foo);
})();
(function() {
"use strict";
function foo(o) { return Reflect.has(o); }
assertFalse(foo({}));
assertFalse(foo({}));
%OptimizeFunctionOnNextCall(foo);
assertFalse(foo({}));
})();
(function() {
"use strict";
function foo(o) { return Reflect.has(o); }
assertThrows(foo.bind(undefined, 1));
assertThrows(foo.bind(undefined, undefined));
%OptimizeFunctionOnNextCall(foo);
assertThrows(foo.bind(undefined, 'o'));
})();
// Test Reflect.has within try/catch.
(function() {
"use strict";
function foo() {
try {
return Reflect.has();
} catch (e) {
return 1;
}
}
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
})();
(function() {
"use strict";
const o = {};
function foo(n) {
try {
return Reflect.has(o, n);
} catch (e) {
return 1;
}
}
assertEquals(1, foo({[Symbol.toPrimitive]() { throw new Error(); }}));
assertEquals(1, foo({[Symbol.toPrimitive]() { throw new Error(); }}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo({[Symbol.toPrimitive]() { throw new Error(); }}));
})();