-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1139 from svaarala/es6-function-tostring
Change Function.prototype.toString() to be ES6 compatible
- Loading branch information
Showing
20 changed files
with
1,670 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
36 changes: 36 additions & 0 deletions
36
tests/ecmascript/test-bi-function-proto-tostring-custom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Duktape custom behavior for Function.prototype.toString(). | ||
*/ | ||
|
||
/*--- | ||
{ | ||
"custom": true | ||
} | ||
---*/ | ||
|
||
/*=== | ||
function foo() { [ecmascript code] } | ||
function cos() { [native code] } | ||
function bound foo() { [bound code] } | ||
function bound cos() { [bound code] } | ||
===*/ | ||
|
||
function test() { | ||
var scriptFunc = function foo() {}; | ||
var nativeFunc = Math.cos; | ||
var boundFunc1 = scriptFunc.bind(null, 1); | ||
var boundFunc2 = nativeFunc.bind(null, 1); | ||
|
||
[ scriptFunc, nativeFunc, boundFunc1, boundFunc2 ].forEach(function (v) { | ||
print(String(v)); | ||
}); | ||
|
||
// Lightfunc and some other cases are covered by | ||
// tests/api/test-dev-func-tostring.c. | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (e) { | ||
print(e.stack || e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Function.prototype.toString() requirements were quite general in ES5: | ||
* output must parse as FunctionDeclaration but doesn't need to compile | ||
* into useful code. | ||
* | ||
* ES6 requires that the source code eval()s to an equivalent object or, | ||
* if that's not possible, evals to a SyntaxError. | ||
* | ||
* Duktape 2.x follows the ES6 requirements. | ||
*/ | ||
|
||
/*=== | ||
SyntaxError | ||
SyntaxError | ||
SyntaxError | ||
SyntaxError | ||
===*/ | ||
|
||
function test() { | ||
var scriptFunc = function foo() {}; | ||
var nativeFunc = Math.cos; | ||
var boundFunc1 = scriptFunc.bind(null, 1); | ||
var boundFunc2 = nativeFunc.bind(null, 1); | ||
|
||
[ scriptFunc, nativeFunc, boundFunc1, boundFunc2 ].forEach(function (v) { | ||
try { | ||
var res = eval(String(v)); | ||
print('never here:', typeof res); | ||
} catch (e) { | ||
print(e.name); | ||
} | ||
}); | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (e) { | ||
print(e.stack || e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.