2016-07-13 15:14:54 +00:00
|
|
|
// Copyright 2016 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
|
|
|
|
|
2017-01-11 09:29:57 +00:00
|
|
|
(function TestDeoptFromComputedNameInObjectLiteral() {
|
2016-07-13 15:14:54 +00:00
|
|
|
function f() {
|
|
|
|
var o = {
|
|
|
|
toString: function() {
|
|
|
|
%DeoptimizeFunction(f);
|
|
|
|
return "x";
|
|
|
|
}
|
|
|
|
};
|
2019-06-12 14:00:50 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
[o]() {
|
|
|
|
return 23;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
%PrepareFunctionForOptimization(f);
|
2016-07-13 15:14:54 +00:00
|
|
|
assertEquals(23, f().x());
|
|
|
|
assertEquals(23, f().x());
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(23, f().x());
|
|
|
|
})();
|
|
|
|
|
2017-01-11 09:29:57 +00:00
|
|
|
(function TestDeoptFromComputedNameInObjectLiteralWithModifiedPrototype() {
|
|
|
|
// The prototype chain should not be used if the definition
|
|
|
|
// happens in the object literal.
|
|
|
|
|
|
|
|
Object.defineProperty(Object.prototype, 'x_proto', {
|
2019-06-12 14:00:50 +00:00
|
|
|
get: function() {
|
2017-01-11 09:29:57 +00:00
|
|
|
return 21;
|
|
|
|
},
|
2019-06-12 14:00:50 +00:00
|
|
|
set: function() {}
|
2017-01-11 09:29:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function f() {
|
|
|
|
var o = {
|
|
|
|
toString: function() {
|
|
|
|
%DeoptimizeFunction(f);
|
|
|
|
return "x_proto";
|
|
|
|
}
|
|
|
|
};
|
2019-06-12 14:00:50 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
[o]() {
|
|
|
|
return 23;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
%PrepareFunctionForOptimization(f);
|
2017-01-11 09:29:57 +00:00
|
|
|
assertEquals(23, f().x_proto());
|
|
|
|
assertEquals(23, f().x_proto());
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(23, f().x_proto());
|
|
|
|
|
|
|
|
delete Object.prototype.c;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestDeoptFromComputedNameInClassLiteral() {
|
2016-07-13 15:14:54 +00:00
|
|
|
function g() {
|
|
|
|
var o = {
|
|
|
|
toString: function() {
|
|
|
|
%DeoptimizeFunction(g);
|
|
|
|
return "y";
|
|
|
|
}
|
|
|
|
};
|
2019-06-12 14:00:50 +00:00
|
|
|
|
2016-07-13 15:14:54 +00:00
|
|
|
class C {
|
2019-06-12 14:00:50 +00:00
|
|
|
[o]() {
|
|
|
|
return 42;
|
|
|
|
}
|
2016-07-13 15:14:54 +00:00
|
|
|
}
|
2019-06-12 14:00:50 +00:00
|
|
|
|
2016-07-13 15:14:54 +00:00
|
|
|
return new C();
|
2019-06-12 14:00:50 +00:00
|
|
|
};
|
|
|
|
%PrepareFunctionForOptimization(g);
|
2016-07-13 15:14:54 +00:00
|
|
|
assertEquals(42, g().y());
|
|
|
|
assertEquals(42, g().y());
|
|
|
|
%OptimizeFunctionOnNextCall(g);
|
|
|
|
assertEquals(42, g().y());
|
|
|
|
})();
|