mirror of https://github.com/tc39/test262.git
add Function.prototype.toString tests, conforming to proposed revision
See the proposal at https://tc39.github.io/Function-prototype-toString-revision/
This commit is contained in:
parent
c15079e741
commit
6b7cbb5035
|
@ -0,0 +1 @@
|
|||
const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]+\b\w+\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/;
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-createdynamicfunction
|
||||
description: Function.prototype.toString on a function created with the Function constructor
|
||||
---*/
|
||||
|
||||
let f = /* before */Function("a", " /* a */ b, c /* b */ //", "/* c */ ; /* d */ //")/* after */;
|
||||
|
||||
assert.sameValue(f.toString(), "function anonymous(a, /* a */ b, c /* b */ //\n) {/* c */ ; /* d */ //\n}");
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-createdynamicfunction
|
||||
description: Function.prototype.toString on a generator function created with the GeneratorFunction constructor
|
||||
---*/
|
||||
|
||||
let GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor;
|
||||
let g = /* before */GeneratorFunction("a", " /* a */ b, c /* b */ //", "/* c */ yield yield; /* d */ //")/* after */;
|
||||
|
||||
assert.sameValue(g.toString(), "function* anonymous(a, /* a */ b, c /* b */ //\n) {/* c */ yield yield; /* d */ //\n}");
|
|
@ -5,7 +5,7 @@
|
|||
es5id: 15.3.4.2_A12
|
||||
description: >
|
||||
The Function.prototype.toString function is not generic; it throws
|
||||
a TypeError exception if its this value is not a Function object.
|
||||
a TypeError exception if its this value is not a callable object.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
es5id: 15.3.4.2_A13
|
||||
description: >
|
||||
The toString function is not generic; it throws a TypeError
|
||||
exception if its this value is not a Function object.
|
||||
exception if its this value is not a callable object.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
es5id: 15.3.4.2_A14
|
||||
description: >
|
||||
The toString function is not generic; it throws a TypeError
|
||||
exception if its this value is not a Function object.
|
||||
exception if its this value is not a callable object.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright 2011 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: >
|
||||
The toString function is not generic; it throws a TypeError exception if
|
||||
its this value is not a Function object.
|
||||
es5id: 15.3.4.2_A15
|
||||
description: >
|
||||
Whether or not they are callable, RegExp objects are not Function
|
||||
objects, so toString should throw a TypeError.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Function.prototype.toString.call(/x/);
|
||||
});
|
|
@ -4,7 +4,7 @@
|
|||
/*---
|
||||
info: >
|
||||
The toString function is not generic; it throws a TypeError exception if
|
||||
its this value is not a Function object.
|
||||
its this value is not a callable object.
|
||||
es5id: 15.3.4.2_A16
|
||||
description: >
|
||||
The String constructor, given an object, should invoke that
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-arrow-function-definitions-runtime-semantics-evaluation
|
||||
description: Function.prototype.toString on an arrow function
|
||||
---*/
|
||||
|
||||
let f = /* before */( /* a */ a /* b */ , /* c */ b /* d */ ) /* e */ => /* f */ { /* g */ ; /* h */ }/* after */;
|
||||
let g = /* before */( /* a */ ) /* b */ => /* c */ 0/* after */;
|
||||
let h = /* before */a /* a */ => /* b */ 0/* after */;
|
||||
|
||||
assert.sameValue(f.toString(), "( /* a */ a /* b */ , /* c */ b /* d */ ) /* e */ => /* f */ { /* g */ ; /* h */ }");
|
||||
assert.sameValue(g.toString(), "( /* a */ ) /* b */ => /* c */ 0");
|
||||
assert.sameValue(h.toString(), "a /* a */ => /* b */ 0");
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function.prototype.tostring
|
||||
description: Function.prototype.toString on bound function exotic objects
|
||||
includes: [nativeFunctionMatcher.js]
|
||||
---*/
|
||||
|
||||
let f = function(){}.bind(null);
|
||||
|
||||
assert(NATIVE_FUNCTION_RE.test("" + f), "looks pretty much like a NativeFunction");
|
11
test/built-ins/Function/prototype/toString/class-declaration-complex-heritage.js
vendored
Normal file
11
test/built-ins/Function/prototype/toString/class-declaration-complex-heritage.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-bindingclassdeclarationevaluation
|
||||
description: Function.prototype.toString on a class declaration (with complex heritage)
|
||||
---*/
|
||||
|
||||
/* before */class /* a */ A /* b */ extends /* c */ class /* d */ B /* e */ { /* f */ } /* g */ { /* h */ }/* after */
|
||||
|
||||
assert.sameValue(A.toString(), "class /* a */ A /* b */ extends /* c */ class /* d */ B /* e */ { /* f */ } /* g */ { /* h */ }");
|
13
test/built-ins/Function/prototype/toString/class-declaration-explicit-ctor.js
vendored
Normal file
13
test/built-ins/Function/prototype/toString/class-declaration-explicit-ctor.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-bindingclassdeclarationevaluation
|
||||
description: Function.prototype.toString on a class declaration (explicit constructor)
|
||||
---*/
|
||||
|
||||
/* before */class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }/* after */
|
||||
|
||||
assert.sameValue(A.toString(), "class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }");
|
||||
|
||||
function B(){}
|
15
test/built-ins/Function/prototype/toString/class-declaration-implicit-ctor.js
vendored
Normal file
15
test/built-ins/Function/prototype/toString/class-declaration-implicit-ctor.js
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-bindingclassdeclarationevaluation
|
||||
description: Function.prototype.toString on a class declaration (implicit constructor)
|
||||
---*/
|
||||
|
||||
/* before */class /* a */ A /* b */ { /* c */ }/* after */
|
||||
/* before */class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }/* after */
|
||||
/* before */class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }/* after */
|
||||
|
||||
assert.sameValue(A.toString(), "class /* a */ A /* b */ { /* c */ }");
|
||||
assert.sameValue(B.toString(), "class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }");
|
||||
assert.sameValue(C.toString(), "class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }");
|
13
test/built-ins/Function/prototype/toString/class-expression-explicit-ctor.js
vendored
Normal file
13
test/built-ins/Function/prototype/toString/class-expression-explicit-ctor.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-class-definitions-runtime-semantics-evaluation
|
||||
description: Function.prototype.toString on a class expression (explicit constructor)
|
||||
---*/
|
||||
|
||||
let A = /* before */class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }/* after */;
|
||||
|
||||
assert.sameValue(A.toString(), "class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }");
|
||||
|
||||
function B(){}
|
15
test/built-ins/Function/prototype/toString/class-expression-implicit-ctor.js
vendored
Normal file
15
test/built-ins/Function/prototype/toString/class-expression-implicit-ctor.js
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-class-definitions-runtime-semantics-evaluation
|
||||
description: Function.prototype.toString on a class expression (implicit constructor)
|
||||
---*/
|
||||
|
||||
let A = /* before */class /* a */ A /* b */ { /* c */ }/* after */;
|
||||
let B = /* before */class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }/* after */;
|
||||
let C = /* before */class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }/* after */;
|
||||
|
||||
assert.sameValue(A.toString(), "class /* a */ A /* b */ { /* c */ }");
|
||||
assert.sameValue(B.toString(), "class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }");
|
||||
assert.sameValue(C.toString(), "class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }");
|
11
test/built-ins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js
vendored
Normal file
11
test/built-ins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
|
||||
description: Function.prototype.toString on a function with a non-simple parameter list
|
||||
---*/
|
||||
|
||||
/* before */function /* a */ f /* b */ ( /* c */ a /* d */ = /* e */ 0 /* f */ , /* g */ { /* h */ b /* i */ = /* j */ 0 /* k */ } /* l */ ) /* m */ { /* n */ }/* after */
|
||||
|
||||
assert.sameValue(f.toString(), "function /* a */ f /* b */ ( /* c */ a /* d */ = /* e */ 0 /* f */ , /* g */ { /* h */ b /* i */ = /* j */ 0 /* k */ } /* l */ ) /* m */ { /* n */ }");
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
|
||||
description: Function.prototype.toString on a function declaration
|
||||
---*/
|
||||
|
||||
/* before */function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */
|
||||
|
||||
assert.sameValue(f.toString(), "function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }");
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function-definitions-runtime-semantics-evaluation
|
||||
description: Function.prototype.toString on a function expression
|
||||
---*/
|
||||
|
||||
let f = /* before */function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */;
|
||||
|
||||
assert.sameValue(f.toString(), "function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }");
|
11
test/built-ins/Function/prototype/toString/generator-function-declaration.js
vendored
Normal file
11
test/built-ins/Function/prototype/toString/generator-function-declaration.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject
|
||||
description: Function.prototype.toString on a generator function declaration
|
||||
---*/
|
||||
|
||||
/* before */function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }/* after */
|
||||
|
||||
assert.sameValue(g.toString(), "function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }");
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: Function.prototype.toString on a generator function expression
|
||||
---*/
|
||||
|
||||
let g = /* before */function /* a */ * /* b */ name /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }/* after */
|
||||
|
||||
assert.sameValue(g.toString(), "function /* a */ * /* b */ name /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a generator method
|
||||
---*/
|
||||
|
||||
let f = { /* before */* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }.f;
|
||||
let g = { /* before */* /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.g;
|
||||
|
||||
assert.sameValue(f.toString(), "* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }");
|
||||
assert.sameValue(g.toString(), "* /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a getter (class; static)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor(class { static /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }, "f").get;
|
||||
let g = Object.getOwnPropertyDescriptor(class { static /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "g").get;
|
||||
|
||||
assert.sameValue(f.toString(), "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }");
|
||||
assert.sameValue(g.toString(), "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a getter (class)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor(class { /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }.prototype, "f").get;
|
||||
let g = Object.getOwnPropertyDescriptor(class { /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.prototype, "g").get;
|
||||
|
||||
assert.sameValue(f.toString(), "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }");
|
||||
assert.sameValue(g.toString(), "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a getter (object)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor({ /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }, "f").get;
|
||||
let g = Object.getOwnPropertyDescriptor({ /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "g").get;
|
||||
|
||||
assert.sameValue(f.toString(), "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }");
|
||||
assert.sameValue(g.toString(), "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }");
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function.prototype.tostring
|
||||
description: Function.prototype.toString on well-known intrinsic function objects
|
||||
includes: [nativeFunctionMatcher.js]
|
||||
---*/
|
||||
|
||||
let intrinsics = {
|
||||
Array, ArrayBuffer, Boolean, DataView, Date, decodeURI, decodeURIComponent, encodeURI,
|
||||
encodeURIComponent, Error, eval, EvalError, Float32Array, Float64Array, Function, Int8Array,
|
||||
Int16Array, Int32Array, isFinite, isNaN, Map, Number, Object, parseFloat, parseInt, Promise,
|
||||
Proxy, RangeError, ReferenceError, RegExp, Set, String, Symbol, SyntaxError, TypeError,
|
||||
Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, URIError, WeakMap, WeakSet,
|
||||
};
|
||||
|
||||
for (let intrinsicName in intrinsics) {
|
||||
let intrinsic = intrinsics[intrinsicName];
|
||||
let str = Function.prototype.toString.call(intrinsic);
|
||||
assert.sameValue(typeof str, "string");
|
||||
assert(RegExp('\\b' + intrinsicName + '\\b').test(str), "contains its name");
|
||||
assert(NATIVE_FUNCTION_RE.test(str), "looks pretty much like a NativeFunction");
|
||||
}
|
36
test/built-ins/Function/prototype/toString/line-terminator-normalisation-CR-LF.js
vendored
Normal file
36
test/built-ins/Function/prototype/toString/line-terminator-normalisation-CR-LF.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
|
||||
description: Function.prototype.toString line terminator normalisation (CR-LF)
|
||||
info: >
|
||||
Function.prototype.toString should normalise line terminator sequences to Line Feed characters.
|
||||
This file uses (Carriage Return, Line Feed) sequences as line terminators.
|
||||
---*/
|
||||
|
||||
// before
|
||||
function
|
||||
// a
|
||||
f
|
||||
// b
|
||||
(
|
||||
// c
|
||||
x
|
||||
// d
|
||||
,
|
||||
// e
|
||||
y
|
||||
// f
|
||||
)
|
||||
// g
|
||||
{
|
||||
// h
|
||||
;
|
||||
// i
|
||||
;
|
||||
// j
|
||||
}
|
||||
// after
|
||||
|
||||
assert.sameValue(f.toString(), "function\n// a\nf\n// b\n(\n// c\nx\n// d\n,\n// e\ny\n// f\n)\n// g\n{\n// h\n;\n// i\n;\n// j\n}");
|
1
test/built-ins/Function/prototype/toString/line-terminator-normalisation-CR.js
vendored
Normal file
1
test/built-ins/Function/prototype/toString/line-terminator-normalisation-CR.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
description: Function.prototype.toString line terminator normalisation (CR)
info: >
Function.prototype.toString should normalise line terminator sequences to Line Feed characters.
This file uses Carriage Return characters as line terminators.
---*/
// before
function
// a
f
// b
(
// c
x
// d
,
// e
y
// f
)
// g
{
// h
;
// i
;
// j
}
// after
assert.sameValue(f.toString(), "function\n// a\nf\n// b\n(\n// c\nx\n// d\n,\n// e\ny\n// f\n)\n// g\n{\n// h\n;\n// i\n;\n// j\n}");
|
36
test/built-ins/Function/prototype/toString/line-terminator-normalisation-LF.js
vendored
Normal file
36
test/built-ins/Function/prototype/toString/line-terminator-normalisation-LF.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject
|
||||
description: Function.prototype.toString line terminator normalisation (LF)
|
||||
info: >
|
||||
Function.prototype.toString should normalise line terminator sequences to Line Feed characters.
|
||||
This file uses Line Feed characters as line terminators.
|
||||
---*/
|
||||
|
||||
// before
|
||||
function
|
||||
// a
|
||||
f
|
||||
// b
|
||||
(
|
||||
// c
|
||||
x
|
||||
// d
|
||||
,
|
||||
// e
|
||||
y
|
||||
// f
|
||||
)
|
||||
// g
|
||||
{
|
||||
// h
|
||||
;
|
||||
// i
|
||||
;
|
||||
// j
|
||||
}
|
||||
// after
|
||||
|
||||
assert.sameValue(f.toString(), "function\n// a\nf\n// b\n(\n// c\nx\n// d\n,\n// e\ny\n// f\n)\n// g\n{\n// h\n;\n// i\n;\n// j\n}");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-definemethod
|
||||
description: Function.prototype.toString on a method (class; static)
|
||||
---*/
|
||||
|
||||
let f = class { static /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f;
|
||||
let g = class { static /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.g;
|
||||
|
||||
assert.sameValue(f.toString(), "f /* a */ ( /* b */ ) /* c */ { /* d */ }");
|
||||
assert.sameValue(g.toString(), "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-definemethod
|
||||
description: Function.prototype.toString on a method (class)
|
||||
---*/
|
||||
|
||||
let f = class { /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.prototype.f;
|
||||
let g = class { /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.prototype.g;
|
||||
|
||||
assert.sameValue(f.toString(), "f /* a */ ( /* b */ ) /* c */ { /* d */ }");
|
||||
assert.sameValue(g.toString(), "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-definemethod
|
||||
description: Function.prototype.toString on a method (object)
|
||||
---*/
|
||||
|
||||
let f = { /* before */[ /* a */ "f" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.f;
|
||||
let g = { [ { a(){} }.a ](){ } }["a(){}"];
|
||||
|
||||
assert.sameValue(f.toString(), "[ /* a */ \"f\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }");
|
||||
assert.sameValue("" + g, "[ { a(){} }.a ](){ }");
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-definemethod
|
||||
description: Function.prototype.toString on a method (object)
|
||||
---*/
|
||||
|
||||
let f = { /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f;
|
||||
|
||||
assert.sameValue(f.toString(), "f /* a */ ( /* b */ ) /* c */ { /* d */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a setter (class; static)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor(class { static /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }, "f").set;
|
||||
let g = Object.getOwnPropertyDescriptor(class { static /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "g").set;
|
||||
|
||||
assert.sameValue(f.toString(), "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }");
|
||||
assert.sameValue(g.toString(), "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a setter (class)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor(class { /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }.prototype, "f").set;
|
||||
let g = Object.getOwnPropertyDescriptor(class { /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }.prototype, "g").set;
|
||||
|
||||
assert.sameValue(f.toString(), "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }");
|
||||
assert.sameValue(g.toString(), "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }");
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
|
||||
description: Function.prototype.toString on a setter (object)
|
||||
---*/
|
||||
|
||||
let f = Object.getOwnPropertyDescriptor({ /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }, "f").set;
|
||||
let g = Object.getOwnPropertyDescriptor({ /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "g").set;
|
||||
|
||||
assert.sameValue(f.toString(), "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }");
|
||||
assert.sameValue(g.toString(), "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }");
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-function.prototype.tostring
|
||||
description: Function.prototype.toString on a function with Unicode escape sequences
|
||||
info: >
|
||||
Function.prototype.toString returns a slice of the source text before
|
||||
any potential Unicode escape sequence substitution in identifiers
|
||||
---*/
|
||||
|
||||
function \u0061(\u{62}, \u0063) { \u0062 = \u{00063}; return b; }
|
||||
|
||||
assert.sameValue(a.toString(), "function \\u0061(\\u{62}, \\u0063) { \\u0062 = \\u{00063}; return b; }");
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2016 Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Provides a regex that makes a best-effort determination that the tested
|
||||
string matches the NativeFunction grammar production without requiring a
|
||||
correct tokeniser
|
||||
includes: [nativeFunctionHelper.js]
|
||||
---*/
|
||||
|
||||
if (!(
|
||||
NATIVE_FUNCTION_RE.test('function(){[native function]}') &&
|
||||
NATIVE_FUNCTION_RE.test('function(){ [native function] }') &&
|
||||
NATIVE_FUNCTION_RE.test('function ( ) { [ native function ] }') &&
|
||||
NATIVE_FUNCTION_RE.test('function a(){ [native function] }') &&
|
||||
NATIVE_FUNCTION_RE.test('function a(){ /* } */ [native function] }') &&
|
||||
!NATIVE_FUNCTION_RE.test('') &&
|
||||
!NATIVE_FUNCTION_RE.test('native function') &&
|
||||
!NATIVE_FUNCTION_RE.test('function(){}') &&
|
||||
!NATIVE_FUNCTION_RE.test('function(){ "native function" }') &&
|
||||
!NATIVE_FUNCTION_RE.test('function(){ [] native function }')
|
||||
)) $ERROR('NATIVE_FUNCTION_RE failed');
|
Loading…
Reference in New Issue