Skip to content

Commit

Permalink
vm: use SetterCallback to set func declarations
Browse files Browse the repository at this point in the history
Currently, when in strict mode, function
declarations are copied on the sandbox by
CopyProperties(), which is not necessary
and will break when CP is removed.

This change maintains current behavior,
letting GlobalPropertySetterCallback
copy functions on the sandbox instead
of using CP to do the task.

PR-URL: #12051
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
AnnaMag authored and italoacasas committed Apr 10, 2017
1 parent ffbcfdf commit 2f88de1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,17 @@ class ContextifyContext {
// false for vmResult.x = 5 where vmResult = vm.runInContext();
bool is_contextual_store = ctx->global_proxy() != args.This();

if (!is_declared && args.ShouldThrowOnError() && is_contextual_store)
// Indicator to not return before setting (undeclared) function declarations
// on the sandbox in strict mode, i.e. args.ShouldThrowOnError() = true.
// True for 'function f() {}', 'this.f = function() {}',
// 'var f = function()'.
// In effect only for 'function f() {}' because
// var f = function(), is_declared = true
// this.f = function() {}, is_contextual_store = false.
bool is_function = value->IsFunction();

if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
!is_function)
return;

ctx->sandbox()->Set(property, value);
Expand Down

0 comments on commit 2f88de1

Please sign in to comment.