diff --git a/src/node_contextify.cc b/src/node_contextify.cc index a6e3d93aa820e3..bc6c468aaf4218 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -432,7 +432,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);