API call to re-copy internal built-in references from target object #566
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ecmascript semantics differentiate between the current value and the initial value of certain built-ins. For example for Array constructor:
Duktape implements this internally by keeping an internal array (
thr->builtins[]
) of built-in object references needed to implement correct semantics.This is a current limitation in sandboxing however: there's no way to replace these internal references which means that even if sandboxing code replaces e.g.
Array.prototype
with a custom value, the original Array prototype may still be referenced when one creates an Array literal.This pull request is a possible solution: add an API call which copies current values of the important built-in references from a target object into the internal reference array. For example,
obj.Duktape
would be copied tothr->builtins[DUK_BIDX_DUKTAPE]
.Compared to other alternatives this is nice because the internal structure, the array model or its indices, is not exposed. Adding or removing values from the internal array has no API impact, but will still correctly update any new internal references required for new semantics.
Open issues:
duk_set_global_object()
and resolve its limitations.Tasks:
duk_set_global_object()
: can it be deprecated (and removed in Duktape 2.x) with this API call in place?