Skip to content

Commit

Permalink
fix setting js options on the wrong object
Browse files Browse the repository at this point in the history
previos to this we were getting a possibly unexported variable "options"
and setting values to it. But the exported options could not have a
local variable with the same name ...

This also fixes a test to specifically need this to work.
  • Loading branch information
mstoykov authored and na-- committed May 21, 2020
1 parent 923f886 commit e148773
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (b *Bundle) Instantiate() (bi *BundleInstance, instErr error) {
bi.exports[k] = fn
}

jsOptions := rt.Get("options")
jsOptions := exports.Get("options")
var jsOptionsObj *goja.Object
if jsOptions == nil || goja.IsNull(jsOptions) || goja.IsUndefined(jsOptions) {
jsOptionsObj = rt.NewObject()
Expand Down
16 changes: 8 additions & 8 deletions js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@ func TestOptionsSettingToScript(t *testing.T) {
func TestOptionsPropagationToScript(t *testing.T) {
t.Parallel()
data := `
var options = { setupTimeout: "1s", myOption: "test" };
exports.options = options;
exports.options = { setupTimeout: "1s", myOption: "test" };
exports.default = function() {
if (options.external) {
if (exports.options.external) {
throw new Error("Unexpected property external!");
}
if (options.myOption != "test") {
throw new Error("expected myOption to remain unchanged but it was '" + options.myOption + "'");
if (exports.options.myOption != "test") {
throw new Error("expected myOption to remain unchanged but it was '" + exports.options.myOption + "'");
}
if (options.setupTimeout != __ENV.expectedSetupTimeout) {
throw new Error("expected setupTimeout to be " + __ENV.expectedSetupTimeout + " but it was " + options.setupTimeout);
if (exports.options.setupTimeout != __ENV.expectedSetupTimeout) {
throw new Error("expected setupTimeout to be " + __ENV.expectedSetupTimeout + " but it was " + exports.options.setupTimeout);
}
};`
};
`

expScriptOptions := lib.Options{SetupTimeout: types.NullDurationFrom(1 * time.Second)}
r1, err := getSimpleRunner("/script.js", data,
Expand Down

0 comments on commit e148773

Please sign in to comment.