2017-08-30 19:11:52 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
// Common pattern in Webpack 3 generated bundles, see
|
|
|
|
// https://github.com/webpack/webpack/issues/5600 for details.
|
|
|
|
(function ObjectConstructorWithKnownFunction() {
|
|
|
|
"use strict";
|
|
|
|
class A {
|
|
|
|
bar() { return this; }
|
|
|
|
};
|
|
|
|
function foo(a) {
|
|
|
|
return Object(a.bar)();
|
|
|
|
}
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-08-30 19:11:52 +00:00
|
|
|
assertEquals(undefined, foo(new A));
|
|
|
|
assertEquals(undefined, foo(new A));
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals(undefined, foo(new A));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function ObjectConstructorWithString() {
|
|
|
|
"use strict";
|
|
|
|
function foo() {
|
|
|
|
return Object("a");
|
|
|
|
}
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-08-30 19:11:52 +00:00
|
|
|
assertEquals('object', typeof foo());
|
|
|
|
assertEquals('object', typeof foo());
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertEquals('object', typeof foo());
|
|
|
|
})();
|
2017-09-08 07:19:01 +00:00
|
|
|
|
|
|
|
// Object constructor subclassing via Class Factories, see
|
|
|
|
// https://twitter.com/FremyCompany/status/905977048006402048
|
|
|
|
// for the hint.
|
|
|
|
(function ObjectConstructorSubClassing() {
|
|
|
|
"use strict";
|
|
|
|
const Factory = Base => class A extends Base {};
|
|
|
|
const A = Factory(Object);
|
|
|
|
function foo() {
|
|
|
|
return new A(1, 2, 3);
|
|
|
|
}
|
2019-03-01 10:19:54 +00:00
|
|
|
%PrepareFunctionForOptimization(foo);
|
2017-09-08 07:19:01 +00:00
|
|
|
assertInstanceof(foo(), A);
|
|
|
|
assertInstanceof(foo(), Object);
|
|
|
|
assertInstanceof(foo(), A);
|
|
|
|
assertInstanceof(foo(), Object);
|
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
|
|
assertInstanceof(foo(), A);
|
|
|
|
assertInstanceof(foo(), Object);
|
|
|
|
})();
|