You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
991 B

/*
* Test basic asm.js compatibility. This should be a given because
* asm.js is a strict subset of Javascript.
*/
/*===
undefined
===*/
/* Ensure that strict mode is detected even if followed by a 'use asm'. */
function declarationTest() {
"use asm";
"use strict";
print(typeof this); // strict: 'undefined', non-strict: 'object'
}
try {
declarationTest.call(undefined);
} catch (e) {
print(e);
}
/*===
5
===*/
/* Example from asm.js spec: http://asmjs.org/spec/latest/.
* Ensure that it works as expected, ignoring asm.js mode.
*/
function DiagModule(stdlib) {
"use asm";
var sqrt = stdlib.Math.sqrt;
function square(x) {
x = +x;
return +(x*x);
}
function diag(x, y) {
x = +x;
y = +y;
return +sqrt(square(x) + square(y));
}
return { diag: diag };
}
try {
var mod = DiagModule(this); // this = global object
print(mod.diag(3, 4)); // -> 5
} catch (e) {
print(e);
}