mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 08:24:38 +00:00

Upgrade to the latest branch-head for V8 4.5. For the full commit log see https://github.com/v8/v8-git-mirror/commits/4.5.103.24 PR-URL: https://github.com/nodejs/node/pull/2509 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
169 lines
3.5 KiB
JavaScript
169 lines
3.5 KiB
JavaScript
// Copyright 2015 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: --strong-mode --allow-natives-syntax
|
|
|
|
"use strict";
|
|
|
|
function pre_inc(x) {
|
|
return ++x;
|
|
}
|
|
|
|
function post_inc(x) {
|
|
return x++;
|
|
}
|
|
|
|
function pre_dec(x) {
|
|
return --x;
|
|
}
|
|
|
|
function post_dec(x) {
|
|
return x--;
|
|
}
|
|
|
|
function getTestFuncs() {
|
|
return [
|
|
function(x){
|
|
"use strong";
|
|
let y = x;
|
|
assertEquals(++y, pre_inc(x));
|
|
try {
|
|
assertEquals(x+1, y)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let y = x;
|
|
assertEquals(y++, post_inc(x));
|
|
try {
|
|
assertEquals(x+1, y)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let y = x;
|
|
assertEquals(--y, pre_dec(x));
|
|
try {
|
|
assertEquals(x-1, y)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let y = x;
|
|
assertEquals(y--, post_dec(x));
|
|
try {
|
|
assertEquals(x-1, y)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let obj = { foo: x };
|
|
let y = ++obj.foo;
|
|
assertEquals(y, pre_inc(x));
|
|
try {
|
|
assertEquals(x+1, obj.foo)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let obj = { foo: x };
|
|
let y = obj.foo++;
|
|
assertEquals(y, post_inc(x));
|
|
try {
|
|
assertEquals(x+1, obj.foo)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let obj = { foo: x };
|
|
let y = --obj.foo;
|
|
assertEquals(y, pre_dec(x));
|
|
try {
|
|
assertEquals(x-1, obj.foo)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
function(x){
|
|
"use strong";
|
|
let obj = { foo: x };
|
|
let y = obj.foo--;
|
|
assertEquals(y, post_dec(x));
|
|
try {
|
|
assertEquals(x-1, obj.foo)
|
|
} catch (e) {
|
|
assertUnreachable();
|
|
}
|
|
},
|
|
];
|
|
}
|
|
|
|
let nonNumberValues = [
|
|
{},
|
|
(function(){}),
|
|
[],
|
|
(class Foo {}),
|
|
"",
|
|
"foo",
|
|
"NaN",
|
|
Object(""),
|
|
false,
|
|
null,
|
|
undefined
|
|
];
|
|
|
|
// Check prior input of None works
|
|
for (let func of getTestFuncs()) {
|
|
for (let value of nonNumberValues) {
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%OptimizeFunctionOnNextCall(func);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%DeoptimizeFunction(func);
|
|
}
|
|
}
|
|
|
|
// Check prior input of Smi works
|
|
for (let func of getTestFuncs()) {
|
|
func(1);
|
|
func(1);
|
|
func(1);
|
|
for (let value of nonNumberValues) {
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%OptimizeFunctionOnNextCall(func);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%DeoptimizeFunction(func);
|
|
}
|
|
}
|
|
|
|
// Check prior input of Number works
|
|
for (let func of getTestFuncs()) {
|
|
func(9999999999999);
|
|
func(9999999999999);
|
|
func(9999999999999);
|
|
for (let value of nonNumberValues) {
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%OptimizeFunctionOnNextCall(func);
|
|
assertThrows(function(){func(value)}, TypeError);
|
|
%DeoptimizeFunction(func);
|
|
}
|
|
}
|