Improve date binding compatibility

This commit is contained in:
dcodeIO 2018-11-11 10:43:17 +01:00
parent 1fad3d26c7
commit 9ab7384122
6 changed files with 31 additions and 23 deletions

View File

@ -1,10 +1,12 @@
export declare function UTC(
// NOTE: Using i32 below saves us a f64.convert_s instruction and moves the responsibility for
// converting the value to the WASM/JS boundary.
year: i32,
month: i32,
day: i32,
hour: i32,
minute: i32,
second: i32,
millisecond: i32
millisecond: f64
): f64;
export declare function now(): f64;

View File

@ -12,9 +12,9 @@ export class Date {
hour: i32 = 0,
minute: i32 = 0,
second: i32 = 0,
millisecond: i32 = 0
millisecond: i64 = 0
): i64 {
return <i64>Date_UTC(year, month, day, hour, minute, second, millisecond);
return <i64>Date_UTC(year, month, day, hour, minute, second, <f64>millisecond);
}
@inline static now(): i64 {
@ -31,7 +31,8 @@ export class Date {
return this.value;
}
setTime(value: i64): void {
setTime(value: i64): i64 {
this.value = value;
return value;
}
}

View File

@ -675,7 +675,7 @@ declare class Date {
/** Returns the UTC timestamp of this date in milliseconds. */
getTime(): i64;
/** Sets the UTC timestamp of this date in milliseconds. */
setTime(value: i64): void;
setTime(value: i64): i64;
}
/** Environmental tracing function for debugging purposes. */

View File

@ -442,7 +442,7 @@ declare class Date {
/** Returns the UTC timestamp of this date in milliseconds. */
getTime(): number;
/** Sets the UTC timestamp of this date in milliseconds. */
setTime(value: number): void;
setTime(value: number): number;
}
declare namespace console {

View File

@ -1,10 +1,10 @@
(module
(type $iiiiiiiF (func (param i32 i32 i32 i32 i32 i32 i32) (result f64)))
(type $iiiiiiFF (func (param i32 i32 i32 i32 i32 i32 f64) (result f64)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $F (func (result f64)))
(type $ii (func (param i32) (result i32)))
(type $v (func))
(import "Date" "UTC" (func $~lib/bindings/Date/UTC (param i32 i32 i32 i32 i32 i32 i32) (result f64)))
(import "Date" "UTC" (func $~lib/bindings/Date/UTC (param i32 i32 i32 i32 i32 i32 f64) (result f64)))
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(import "Date" "now" (func $~lib/bindings/Date/now (result f64)))
(memory $0 1)
@ -93,7 +93,7 @@
i32.const 0
i32.const 0
i32.const 0
i32.const 0
f64.const 0
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
i64.const 0
@ -112,7 +112,7 @@
i32.const 0
i32.const 0
i32.const 0
i32.const 0
f64.const 0
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
i64.const 0
@ -131,7 +131,7 @@
i32.const 11
i32.const 0
i32.const 0
i32.const 1
f64.const 1
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
set_global $std/date/creationTime

View File

@ -1,13 +1,13 @@
(module
(type $iiiiiiiF (func (param i32 i32 i32 i32 i32 i32 i32) (result f64)))
(type $iiiiiiFF (func (param i32 i32 i32 i32 i32 i32 f64) (result f64)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $F (func (result f64)))
(type $iIi (func (param i32 i64) (result i32)))
(type $ii (func (param i32) (result i32)))
(type $iI (func (param i32) (result i64)))
(type $iIv (func (param i32 i64)))
(type $iII (func (param i32 i64) (result i64)))
(type $v (func))
(import "Date" "UTC" (func $~lib/bindings/Date/UTC (param i32 i32 i32 i32 i32 i32 i32) (result f64)))
(import "Date" "UTC" (func $~lib/bindings/Date/UTC (param i32 i32 i32 i32 i32 i32 f64) (result f64)))
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(import "Date" "now" (func $~lib/bindings/Date/now (result f64)))
(memory $0 1)
@ -136,10 +136,11 @@
get_local $0
i64.load
)
(func $~lib/date/Date#setTime (; 7 ;) (type $iIv) (param $0 i32) (param $1 i64)
(func $~lib/date/Date#setTime (; 7 ;) (type $iII) (param $0 i32) (param $1 i64) (result i64)
get_local $0
get_local $1
i64.store
get_local $1
)
(func $start (; 8 ;) (type $v)
(local $0 i32)
@ -148,7 +149,7 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $6 i64)
get_global $HEAP_BASE
get_global $~lib/internal/allocator/AL_MASK
i32.add
@ -172,7 +173,7 @@
set_local $4
i32.const 0
set_local $5
i32.const 0
i64.const 0
set_local $6
get_local $0
get_local $1
@ -181,6 +182,7 @@
get_local $4
get_local $5
get_local $6
f64.convert_s/i64
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
end
@ -197,12 +199,10 @@
end
block $~lib/date/Date.UTC|inlined.1 (result i64)
i32.const 1970
set_local $6
i32.const 0
set_local $5
i32.const 1
set_local $4
i32.const 0
set_local $4
i32.const 1
set_local $3
i32.const 0
set_local $2
@ -210,13 +210,16 @@
set_local $1
i32.const 0
set_local $0
get_local $6
i64.const 0
set_local $6
get_local $5
get_local $4
get_local $3
get_local $2
get_local $1
get_local $0
get_local $6
f64.convert_s/i64
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
end
@ -244,7 +247,7 @@
set_local $4
i32.const 0
set_local $5
i32.const 1
i64.const 1
set_local $6
get_local $0
get_local $1
@ -253,6 +256,7 @@
get_local $4
get_local $5
get_local $6
f64.convert_s/i64
call $~lib/bindings/Date/UTC
i64.trunc_s/f64
end
@ -306,6 +310,7 @@
i64.const 1
i64.add
call $~lib/date/Date#setTime
drop
get_global $std/date/date
call $~lib/date/Date#getTime
get_global $std/date/creationTime