mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
parent
dd7d387420
commit
0845d0253a
|
@ -154,6 +154,11 @@ func builtinDate_UTC(call FunctionCall) Value {
|
|||
return toValue_float64(newDateTime(call.ArgumentList, Time.UTC))
|
||||
}
|
||||
|
||||
func builtinDate_now(call FunctionCall) Value {
|
||||
call.ArgumentList = []Value(nil)
|
||||
return builtinDate_UTC(call)
|
||||
}
|
||||
|
||||
// This is a placeholder
|
||||
func builtinDate_toLocaleString(call FunctionCall) Value {
|
||||
date := dateObjectOf(call.thisObject())
|
||||
|
|
10
date_test.go
10
date_test.go
|
@ -3,6 +3,7 @@ package otto
|
|||
import (
|
||||
. "./terst"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
Time "time"
|
||||
)
|
||||
|
@ -131,6 +132,15 @@ func TestDate_UTC(t *testing.T) {
|
|||
test(`Date.UTC(2009, 9, 25)`, "1256428800000")
|
||||
}
|
||||
|
||||
func TestDate_now(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
time := Time.Now()
|
||||
test(`Date.now()`, strconv.FormatInt(epochToInteger(timeToEpoch(time)), 10))
|
||||
test(`Date.now() === Date.now(1,2,3)`, "true")
|
||||
}
|
||||
|
||||
func TestDate_toISOString(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
|
|
1
inline
1
inline
|
@ -483,6 +483,7 @@ sub newContext {
|
|||
$class,
|
||||
"parse", 0,
|
||||
"UTC", 0,
|
||||
"now", 0,
|
||||
),
|
||||
),
|
||||
}),
|
||||
|
|
26
inline.go
26
inline.go
|
@ -3683,6 +3683,25 @@ func _newContext(runtime *_runtime) {
|
|||
call: _nativeCallFunction(builtinDate_UTC),
|
||||
},
|
||||
}
|
||||
now_function := &_object{
|
||||
runtime: runtime,
|
||||
class: "Function",
|
||||
objectClass: _classObject,
|
||||
prototype: runtime.Global.FunctionPrototype,
|
||||
extensible: true,
|
||||
property: map[string]_property{
|
||||
"length": _property{
|
||||
mode: 0,
|
||||
value: Value{
|
||||
_valueType: valueNumber,
|
||||
value: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
value: _functionObject{
|
||||
call: _nativeCallFunction(builtinDate_now),
|
||||
},
|
||||
}
|
||||
runtime.Global.DatePrototype = &_object{
|
||||
runtime: runtime,
|
||||
class: "Date",
|
||||
|
@ -4054,6 +4073,13 @@ func _newContext(runtime *_runtime) {
|
|||
value: UTC_function,
|
||||
},
|
||||
},
|
||||
"now": _property{
|
||||
mode: 0101,
|
||||
value: Value{
|
||||
_valueType: valueObject,
|
||||
value: now_function,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
runtime.Global.DatePrototype.property["constructor"] =
|
||||
|
|
Loading…
Reference in New Issue
Block a user