Skip to content

Instantly share code, notes, and snippets.

@avdg
Last active December 15, 2015 23:04
Show Gist options
  • Save avdg/80265b72c5a0b17e5a48 to your computer and use it in GitHub Desktop.
Save avdg/80265b72c5a0b17e5a48 to your computer and use it in GitHub Desktop.
UglifyJS2 test262 argument object crash test II
// Copyright (c) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 10.6-6-4
description: >
'length' property of arguments object for 0 argument function call
is 0 even with formal parameters
flags: [noStrict]
---*/
function testcase() {
var arguments= undefined;
(function (a,b,c) { assert.sameValue(arguments.length, 0); })();
}
testcase();
function Test262Error(t){this.message=t||""}function testFailed(t){$ERROR(t)}function testRun(t,r,e,o,n,a){if("pass"!==n)throw new Error("Test '"+r+"'failed: "+a)}function assert(t,r){t!==!0&&(void 0===r&&(r="Expected true but got "+String(t)),$ERROR(r))}function testcase(){var t=void 0;!function(r,e,o){assert.sameValue(t.length,0)}()}var strict_mode=!1,NotEarlyErrorString="NotEarlyError",EarlyErrorRePat="^((?!"+NotEarlyErrorString+").)*$",NotEarlyError=new Error(NotEarlyErrorString);Test262Error.prototype.toString=function(){return"Test262Error: "+this.message};var $ERROR;$ERROR=function(t){throw new Test262Error(t)};var print;if("object"==typeof console&&(print=function(){var t=Array.prototype.slice.call(arguments);console.log(t.join(" "))}),"object"==typeof WScript){print=function(){var t=Array.prototype.slice.call(arguments);WScript.Echo(t.join(" "))};var oldError=$ERROR;$ERROR=function(t){print("Test262 Error: "+t),WScript.Quit(1)}}assert._isSameValue=function(t,r){return t===r?0!==t||1/t===1/r:t!==t&&r!==r},assert.sameValue=function(t,r,e){assert._isSameValue(t,r)||(void 0===e?e="":e+=" ",e+="Expected SameValue(«"+String(t)+"», «"+String(r)+"») to be true",$ERROR(e))},assert.notSameValue=function(t,r,e){assert._isSameValue(t,r)&&(void 0===e?e="":e+=" ",e+="Expected SameValue(«"+String(t)+"», «"+String(r)+"») to be false",$ERROR(e))},assert["throws"]=function(t,r,e){if(void 0===r)return void $ERROR("assert.throws requires two arguments: the error constructor and a function to run");void 0===e?e="":e+=" ";try{r()}catch(o){return void("object"!=typeof o||null===o?(e+="Thrown value was not an object!",$ERROR(e)):o.constructor!==t&&(e+="Expected a "+t.name+" but got a "+o.constructor.name,$ERROR(e)))}e+="Expected a "+t.name+" to be thrown but no exception was thrown at all",$ERROR(e)},testcase();
//"no strict";
var strict_mode = false;
var NotEarlyErrorString = "NotEarlyError";
var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$";
var NotEarlyError = new Error(NotEarlyErrorString);
function Test262Error(message) {
this.message = message || "";
}
Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
};
var $ERROR;
$ERROR = function $ERROR(message) {
throw new Test262Error(message);
};
function testFailed(message) {
$ERROR(message);
}
function testRun(id, path, description, codeString, result, error) {
if (result!=="pass") {
throw new Error("Test '" + path + "'failed: " + error);
}
}
// define a default `print` function for async tests where there is no
// global `print`
var print;
// in node use console.log
if (typeof console === "object") {
print = function () {
var args = Array.prototype.slice.call(arguments);
console.log(args.join(" "));
};
}
// in WScript, use WScript.Echo
if (typeof WScript === "object") {
print = function () {
var args = Array.prototype.slice.call(arguments);
WScript.Echo(args.join(" "));
};
// also override $ERROR to force a nonzero exit code exit
// TODO? report syntax errors
var oldError = $ERROR;
$ERROR = function (message) {
print("Test262 Error: " + message);
WScript.Quit(1);
};
}
function assert(mustBeTrue, message) {
if (mustBeTrue === true) {
return;
}
if (message === undefined) {
message = 'Expected true but got ' + String(mustBeTrue);
}
$ERROR(message);
}
assert._isSameValue = function (a, b) {
if (a === b) {
// Handle +/-0 vs. -/+0
return a !== 0 || 1 / a === 1 / b;
}
// Handle NaN vs. NaN
return a !== a && b !== b;
};
assert.sameValue = function (actual, expected, message) {
if (assert._isSameValue(actual, expected)) {
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
message += 'Expected SameValue(«' + String(actual) + '», «' + String(expected) + '») to be true';
$ERROR(message);
};
assert.notSameValue = function (actual, unexpected, message) {
if (!assert._isSameValue(actual, unexpected)) {
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
message += 'Expected SameValue(«' + String(actual) + '», «' + String(unexpected) + '») to be false';
$ERROR(message);
};
assert.throws = function (expectedErrorConstructor, func, message) {
if (func === undefined) {
$ERROR('assert.throws requires two arguments: the error constructor and a function to run');
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!';
$ERROR(message);
} else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message);
}
return;
}
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
};
function testcase() {
var arguments= undefined;
(function (a,b,c) { assert.sameValue(arguments.length, 0); })();
}
testcase();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment