Commit af5edf95 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added Date.now implementation.

parent ff54bafb
...@@ -92,6 +92,7 @@ static const WCHAR getYearW[] = {'g','e','t','Y','e','a','r',0}; ...@@ -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 setYearW[] = {'s','e','t','Y','e','a','r',0};
static const WCHAR UTCW[] = {'U','T','C',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 const WCHAR parseW[] = {'p','a','r','s','e',0};
static inline DateInstance *date_from_jsdisp(jsdisp_t *jsdisp) static inline DateInstance *date_from_jsdisp(jsdisp_t *jsdisp)
...@@ -452,6 +453,17 @@ static inline DOUBLE time_clip(DOUBLE time) ...@@ -452,6 +453,17 @@ static inline DOUBLE time_clip(DOUBLE time)
return floor(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) static SYSTEMTIME create_systemtime(DOUBLE time)
{ {
SYSTEMTIME st; SYSTEMTIME st;
...@@ -2361,6 +2373,15 @@ static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un ...@@ -2361,6 +2373,15 @@ static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres; 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, static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r) jsval_t *r)
{ {
...@@ -2373,19 +2394,11 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -2373,19 +2394,11 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
case DISPATCH_CONSTRUCT: case DISPATCH_CONSTRUCT:
switch(argc) { switch(argc) {
/* ECMA-262 3rd Edition 15.9.3.3 */ /* ECMA-262 3rd Edition 15.9.3.3 */
case 0: { case 0:
FILETIME time; hres = create_date(ctx, NULL, date_now(), &date);
LONGLONG lltime;
GetSystemTimeAsFileTime(&time);
lltime = ((LONGLONG)time.dwHighDateTime<<32)
+ time.dwLowDateTime;
hres = create_date(ctx, NULL, lltime/10000-TIME_EPOCH, &date);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
break; break;
}
/* ECMA-262 3rd Edition 15.9.3.2 */ /* ECMA-262 3rd Edition 15.9.3.2 */
case 1: { case 1: {
...@@ -2454,6 +2467,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -2454,6 +2467,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
static const builtin_prop_t DateConstr_props[] = { static const builtin_prop_t DateConstr_props[] = {
{UTCW, DateConstr_UTC, PROPF_METHOD}, {UTCW, DateConstr_UTC, PROPF_METHOD},
{nowW, DateConstr_now, PROPF_HTML|PROPF_METHOD},
{parseW, DateConstr_parse, PROPF_METHOD} {parseW, DateConstr_parse, PROPF_METHOD}
}; };
......
...@@ -294,6 +294,7 @@ obj = new Date(); ...@@ -294,6 +294,7 @@ obj = new Date();
ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true"); ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
ok(!Date.hasOwnProperty('getTime'), "Date.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(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
ok(!("now" in Date), "now found in Date");
obj = new Number(); obj = new Number();
ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true"); ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
......
...@@ -121,6 +121,7 @@ function test_javascript() { ...@@ -121,6 +121,7 @@ function test_javascript() {
test_exposed("ScriptEngineMajorVersion", g, true); test_exposed("ScriptEngineMajorVersion", g, true);
test_exposed("JSON", g, v >= 8); test_exposed("JSON", g, v >= 8);
test_exposed("now", Date, true);
next_test(); next_test();
} }
......
/*
* 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" ...@@ -52,6 +52,9 @@ xhr.js HTML "xhr.js"
/* @makedep: elements.js */ /* @makedep: elements.js */
elements.js HTML "elements.js" elements.js HTML "elements.js"
/* @makedep: es5.js */
es5.js HTML "es5.js"
/* @makedep: events.js */ /* @makedep: events.js */
events.js HTML "events.js" events.js HTML "events.js"
......
...@@ -3465,6 +3465,7 @@ static void run_js_tests(void) ...@@ -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("xhr.js", NULL, "11");
run_script_as_http_with_mode("elements.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("events.js", NULL, "9");
run_script_as_http_with_mode("navigation.js", NULL, NULL); run_script_as_http_with_mode("navigation.js", NULL, NULL);
run_script_as_http_with_mode("navigation.js", NULL, "11"); run_script_as_http_with_mode("navigation.js", NULL, "11");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment