-
-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add console javascript object for backwards compatibility (#4944)
- Loading branch information
1 parent
dbfa450
commit 60446af
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package javascript | ||
|
||
import "fmt" | ||
|
||
type console struct { | ||
Log | ||
} | ||
|
||
func (c *console) AddToVM(globalName string, vm *VM) error { | ||
console := vm.NewObject() | ||
if err := SetAll(console, | ||
ObjectValueDef{"log", c.logInfo}, | ||
ObjectValueDef{"error", c.logError}, | ||
ObjectValueDef{"warn", c.logWarn}, | ||
ObjectValueDef{"info", c.logInfo}, | ||
ObjectValueDef{"debug", c.logDebug}, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
if err := vm.Set(globalName, console); err != nil { | ||
return fmt.Errorf("unable to set console: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters