mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 15:41:10 +00:00
jscript: Added Date.now implementation.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
ff54bafb43
commit
af5edf9504
|
@ -92,6 +92,7 @@ static const WCHAR getYearW[] = {'g','e','t','Y','e','a','r',0};
|
|||
static const WCHAR setYearW[] = {'s','e','t','Y','e','a','r',0};
|
||||
|
||||
static const WCHAR UTCW[] = {'U','T','C',0};
|
||||
static const WCHAR nowW[] = {'n','o','w',0};
|
||||
static const WCHAR parseW[] = {'p','a','r','s','e',0};
|
||||
|
||||
static inline DateInstance *date_from_jsdisp(jsdisp_t *jsdisp)
|
||||
|
@ -452,6 +453,17 @@ static inline DOUBLE time_clip(DOUBLE time)
|
|||
return floor(time);
|
||||
}
|
||||
|
||||
static double date_now(void)
|
||||
{
|
||||
FILETIME ftime;
|
||||
LONGLONG time;
|
||||
|
||||
GetSystemTimeAsFileTime(&ftime);
|
||||
time = ((LONGLONG)ftime.dwHighDateTime << 32) + ftime.dwLowDateTime;
|
||||
|
||||
return time/10000 - TIME_EPOCH;
|
||||
}
|
||||
|
||||
static SYSTEMTIME create_systemtime(DOUBLE time)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
|
@ -2361,6 +2373,15 @@ static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
|
|||
return hres;
|
||||
}
|
||||
|
||||
/* ECMA-262 5.1 Edition 15.9.4.4 */
|
||||
static HRESULT DateConstr_now(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
||||
{
|
||||
TRACE("\n");
|
||||
|
||||
if(r) *r = jsval_number(date_now());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
||||
jsval_t *r)
|
||||
{
|
||||
|
@ -2373,19 +2394,11 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
|||
case DISPATCH_CONSTRUCT:
|
||||
switch(argc) {
|
||||
/* ECMA-262 3rd Edition 15.9.3.3 */
|
||||
case 0: {
|
||||
FILETIME time;
|
||||
LONGLONG lltime;
|
||||
|
||||
GetSystemTimeAsFileTime(&time);
|
||||
lltime = ((LONGLONG)time.dwHighDateTime<<32)
|
||||
+ time.dwLowDateTime;
|
||||
|
||||
hres = create_date(ctx, NULL, lltime/10000-TIME_EPOCH, &date);
|
||||
case 0:
|
||||
hres = create_date(ctx, NULL, date_now(), &date);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
break;
|
||||
}
|
||||
|
||||
/* ECMA-262 3rd Edition 15.9.3.2 */
|
||||
case 1: {
|
||||
|
@ -2454,6 +2467,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
|
|||
|
||||
static const builtin_prop_t DateConstr_props[] = {
|
||||
{UTCW, DateConstr_UTC, PROPF_METHOD},
|
||||
{nowW, DateConstr_now, PROPF_HTML|PROPF_METHOD},
|
||||
{parseW, DateConstr_parse, PROPF_METHOD}
|
||||
};
|
||||
|
||||
|
|
|
@ -294,6 +294,7 @@ obj = new Date();
|
|||
ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
|
||||
ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
|
||||
ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
|
||||
ok(!("now" in Date), "now found in Date");
|
||||
|
||||
obj = new Number();
|
||||
ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
|
||||
|
|
|
@ -121,6 +121,7 @@ function test_javascript() {
|
|||
test_exposed("ScriptEngineMajorVersion", g, true);
|
||||
|
||||
test_exposed("JSON", g, v >= 8);
|
||||
test_exposed("now", Date, true);
|
||||
|
||||
next_test();
|
||||
}
|
||||
|
|
32
dlls/mshtml/tests/es5.js
Normal file
32
dlls/mshtml/tests/es5.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2018 Jacek Caban for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
function test_date_now() {
|
||||
var now = Date.now();
|
||||
var time = (new Date()).getTime();
|
||||
|
||||
ok(time >= now && time-now < 50, "unexpected Date.now() result " + now + " expected " + time);
|
||||
|
||||
Date.now(1, 2, 3);
|
||||
|
||||
next_test();
|
||||
}
|
||||
|
||||
var tests = [
|
||||
test_date_now
|
||||
];
|
|
@ -52,6 +52,9 @@ xhr.js HTML "xhr.js"
|
|||
/* @makedep: elements.js */
|
||||
elements.js HTML "elements.js"
|
||||
|
||||
/* @makedep: es5.js */
|
||||
es5.js HTML "es5.js"
|
||||
|
||||
/* @makedep: events.js */
|
||||
events.js HTML "events.js"
|
||||
|
||||
|
|
|
@ -3465,6 +3465,7 @@ static void run_js_tests(void)
|
|||
|
||||
run_script_as_http_with_mode("xhr.js", NULL, "11");
|
||||
run_script_as_http_with_mode("elements.js", NULL, "11");
|
||||
run_script_as_http_with_mode("es5.js", NULL, "11");
|
||||
run_script_as_http_with_mode("events.js", NULL, "9");
|
||||
run_script_as_http_with_mode("navigation.js", NULL, NULL);
|
||||
run_script_as_http_with_mode("navigation.js", NULL, "11");
|
||||
|
|
Loading…
Reference in a new issue