Skip to content

Commit 5ebfbc6

Browse files
committed
fix (wasm, builtins): add !js build tag and modify jaza to make the message argument optional
1 parent a40d0b5 commit 5ebfbc6

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

evaluator/builtins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !wasm
1+
//go:build !js || !wasm
22

33
package evaluator
44

evaluator/builtins_wasm.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,23 @@ var builtins = map[string]*object.Builtin{
1818
return newError("Samahani, kiendesha hiki kinapokea hoja 0 au 1, wewe umeweka %d", len(args))
1919
}
2020

21-
if len(args) > 0 && args[0].Type() != object.STRING_OBJ {
21+
if len(args) == 1 && args[0].Type() != object.STRING_OBJ {
2222
return newError(fmt.Sprintf(`Tafadhali tumia alama ya nukuu: "%s"`, args[0].Inspect()))
2323
}
24-
if len(args) == 1 {
25-
// prompt := args[0].(*object.String).Value
26-
// prompt += "\n" //add breakline
27-
fmt.Println("prompt")
28-
} else {
29-
fmt.Println("Nooo")
30-
}
3124

3225
// Get the window.prompt function
3326
jsPromptFunction := js.Global().Get("prompt")
3427
if jsPromptFunction.Type() != js.TypeFunction {
35-
// fmt.Print("prompt function not found")
3628
return newError("prompt function not found")
3729
}
3830

3931
// invoke it!!
40-
result := jsPromptFunction.Invoke(args[0].Inspect())
32+
var result js.Value
33+
if len(args) == 0 {
34+
result = jsPromptFunction.Invoke()
35+
} else {
36+
result = jsPromptFunction.Invoke(args[0].Inspect())
37+
}
4138

4239
// fmt.Println("the arguments", args[0].Inspect())
4340
// fmt.Println("the result of window.prompt", result.String())

0 commit comments

Comments
 (0)