1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-19 19:55:30 +08:00
otto/console.go
Robert Krimen 3c93384f5c Cleanup of stash, property, and object
Use octal to designate write/enumerate/configure (experimental)
Move extensibility responsibility into the stash
Rename propertyStash => objectStash (be congruent with arrayStash, etc.)
Get rid of a bunch of useless methods
Privatize everything ([A-Z] => [a-z_])
gofmt
2012-10-26 15:47:19 -07:00

50 lines
1.1 KiB
Go

package otto
import (
"fmt"
"strings"
"os"
)
func formatForConsole(argumentList []Value) string {
output := []string{}
for _, argument := range argumentList {
output = append(output, fmt.Sprintf("%v", argument))
}
return strings.Join(output, " ")
}
func builtinConsole_log(call FunctionCall) Value {
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList))
return UndefinedValue()
}
func builtinConsole_error(call FunctionCall) Value {
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList))
return UndefinedValue()
}
func builtinConsole_placeholder(call FunctionCall) Value {
// Do nothing, for now
return UndefinedValue()
}
func (runtime *_runtime) newConsole() *_object {
self := runtime.newObject()
self.write(
"log", builtinConsole_log,
"debug", builtinConsole_log,
"info", builtinConsole_log,
"error", builtinConsole_error,
"warn", builtinConsole_error,
"dir", builtinConsole_placeholder,
"time", builtinConsole_placeholder,
"timeEnd", builtinConsole_placeholder,
"trace", builtinConsole_placeholder,
"assert", builtinConsole_placeholder,
)
return self
}