Skip to content

Commit 1277cc5

Browse files
committed
helpers.py - use globalThis as authoritative source of globals to add to exports
1 parent c498576 commit 1277cc5

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

python/pythonmonkey/helpers.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ def new(ctor):
3939
)""", evalOpts)(ctor)
4040
return (lambda *args: newCtor(list(args)))
4141

42-
globalThis = pm.eval('globalThis');
43-
# standard ECMAScript global properties defined in ECMA 262-3 §15.1 except eval as it is ~supplied in pythonmonkey.so
44-
standard_globals = [ "Array", "Boolean", "Date", "decodeURI", "decodeURIComponent", "encodeURI",
45-
"encodeURIComponent", "Error", "EvalError", "Function", "Infinity", "isNaN",
46-
"isFinite", "Math", "NaN", "Number", "Object", "parseInt", "parseFloat",
47-
"RangeError", "ReferenceError", "RegExp", "String", "SyntaxError", "TypeError",
48-
"undefined", "URIError" ]
49-
# SpiderMonkey-specific globals, depending on compile-time options
50-
spidermonkey_extra_globals = [ "escape", "unescape", "uneval", "InternalError", "Script", "XML",
51-
"Namespace", "QName", "File", "Generator", "Iterator", "StopIteration" ]
52-
53-
# Restrict what symbols are exposed to the pythonmonkey module.
42+
# List which symbols are exposed to the pythonmonkey module.
5443
__all__ = [ "new", "typeof" ]
5544

56-
for name in standard_globals + spidermonkey_extra_globals:
57-
if (globalThis['hasOwnProperty'](name)):
58-
globals().update({name: globalThis[name]})
59-
__all__.append(name)
45+
# Add the properties of globalThis (except eval) as exports:
46+
globalThis = pm.eval('globalThis');
47+
48+
exports = pm.eval("""
49+
Object.getOwnPropertyNames(globalThis)
50+
.filter(prop => prop !== 'eval')
51+
.filter(prop => prop[0] !== '_')
52+
.filter(prop => Object.keys(globalThis).indexOf(prop) === -1)
53+
""")
54+
55+
for index in range(0, int(exports.length) - 1):
56+
name = exports[index]
57+
globals().update({name: globalThis[name]})
58+
__all__.append(name)

0 commit comments

Comments
 (0)