NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
1.98k stars 353 forks source link

Fix scope and getter/setter issues #185

Closed NeilFraser closed 4 years ago

NeilFraser commented 4 years ago

Previously a scope object was a regular object with two extra properties tacked on: strict and parentScope. Issue #183 proved that sometimes one needs multiple scopes with different parentScope values. This PR creates a scope object with the above two properties, as well as a third property (‘.object’) that points to the regular object. This allows two scopes to have different parentScopes, while sharing the same object for variables.

Minor API change for advanced threading and serialization.

Resolves #183

There are several places where getters and setters are not supported. Such as array’s .length. If a getter or setter is encountered in one of these places, throw an error, rather than performing invalid behaviour.

Resolves #184