Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring io module should not polute the global scope #459

Open
botic opened this issue May 18, 2022 · 1 comment
Open

Requiring io module should not polute the global scope #459

botic opened this issue May 18, 2022 · 1 comment

Comments

@botic
Copy link
Member

botic commented May 18, 2022

The io module introduces ByteArray and ByteString via defineClass(). This adds both to the engine's global host objects. This prevents using const in the context of i/o.

~ > ringo -e "ByteArray();"
ReferenceError: "ByteArray" is not defined.
	at <expr>:1

~ > ringo -e "const io = require('io'); console.log(ByteArray());"
[ByteArray 0]

I don't see a chance to fix this anyway, but leave this as an issue to discuss for the future. Maybe we find a non-radical solution to this problem.

@botic
Copy link
Member Author

botic commented May 20, 2022

Rewriting this will be fun. The org.ringojs.wrappers.Binary class relies on initialization as host object inside the current RhinoEngine instance. The Java implementation of Binary registers the ByteArray and ByteString subtypes in a Rhino lifecycle hook with:

initClass(scope, prototype, Type.ByteArray);
initClass(scope, prototype, Type.ByteString);

I haven't found why these must be host objects of the engine. But I guess it's because there of CommonJS' Binary/B:

In multi-sandbox scenarios, the implementation should strive to consistently export the same "Binary", "ByteArray", and "ByteString"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant