-
Notifications
You must be signed in to change notification settings - Fork 517
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 #1260 from svaarala/add-global-binding
Add a 'global' binding
- Loading branch information
Showing
6 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Duktape 2.1.0 adds a 'global' binding. Polyfill for earlier versions. | ||
*/ | ||
|
||
if (typeof global === 'undefined') { | ||
(function () { | ||
var global = new Function('return this;')(); | ||
Object.defineProperty(global, 'global', { | ||
value: global, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
})(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 'global' binding based on https://github.com/tc39/proposal-global | ||
*/ | ||
|
||
/*=== | ||
object | ||
true | ||
object | ||
true | ||
true | ||
false | ||
true | ||
===*/ | ||
|
||
function test() { | ||
var pd, g; | ||
|
||
// Standard trick to access global object. | ||
g = new Function('return this')(); | ||
|
||
// proposal-global provides 'global' for cleaner standard access. | ||
print(typeof global); | ||
print(g === global); | ||
|
||
// Attributes in current proposal. | ||
pd = Object.getOwnPropertyDescriptor(g, 'global'); | ||
print(typeof pd); | ||
if (pd) { | ||
print(pd.value === g); | ||
print(pd.writable); | ||
print(pd.enumerable); | ||
print(pd.configurable); | ||
} | ||
} | ||
|
||
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