From 4c391e55ba3a418f358a2ba0dd383a11f673f706 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 4 May 2020 18:37:06 +0300 Subject: [PATCH] Also set "options" on the "exports" not just in the runtime --- js/bundle.go | 4 +++- js/runner_test.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/js/bundle.go b/js/bundle.go index 30dab0bf76d..aae3be50418 100644 --- a/js/bundle.go +++ b/js/bundle.go @@ -227,7 +227,9 @@ func (b *Bundle) Instantiate() (bi *BundleInstance, instErr error) { var jsOptionsObj *goja.Object if jsOptions == nil || goja.IsNull(jsOptions) || goja.IsUndefined(jsOptions) { jsOptionsObj = rt.NewObject() - rt.Set("options", jsOptionsObj) + if err := exports.Set("options", jsOptionsObj); err != nil { + return nil, err + } } else { jsOptionsObj = jsOptions.ToObject(rt) } diff --git a/js/runner_test.go b/js/runner_test.go index 9da3bc11f86..05a943b479a 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -146,6 +146,7 @@ func TestOptionsSettingToScript(t *testing.T) { t.Run(fmt.Sprintf("Variant#%d", i), func(t *testing.T) { t.Parallel() data := variant + ` + exports.options = options; exports.default = function() { if (!options) { throw new Error("Expected options to be defined!");