jscript: Make global constants non-writable in ES5 mode.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2018-05-11 14:43:40 +02:00 committed by Alexandre Julliard
parent 4555828c57
commit 6b1e54a28e
2 changed files with 23 additions and 4 deletions

View File

@ -1087,6 +1087,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
HRESULT init_global(script_ctx_t *ctx) HRESULT init_global(script_ctx_t *ctx)
{ {
unsigned const_flags = ctx->version >= SCRIPTLANGUAGEVERSION_ES5 ? 0 : PROPF_WRITABLE;
jsdisp_t *math, *object_prototype, *constr; jsdisp_t *math, *object_prototype, *constr;
HRESULT hres; HRESULT hres;
@ -1137,14 +1138,14 @@ HRESULT init_global(script_ctx_t *ctx)
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = jsdisp_propput_dontenum(ctx->global, undefinedW, jsval_undefined()); hres = jsdisp_define_data_property(ctx->global, undefinedW, const_flags, jsval_undefined());
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = jsdisp_propput_dontenum(ctx->global, NaNW, jsval_number(NAN)); hres = jsdisp_define_data_property(ctx->global, NaNW, const_flags, jsval_number(NAN));
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = jsdisp_propput_dontenum(ctx->global, InfinityW, jsval_number(INFINITY)); hres = jsdisp_define_data_property(ctx->global, InfinityW, const_flags, jsval_number(INFINITY));
return hres; return hres;
} }

View File

@ -284,6 +284,23 @@ function test_defineProperty() {
next_test(); next_test();
} }
function test_global_properties() {
var o;
/* Make sure that global properties are not writable. */
o = NaN;
NaN = 1;
ok(isNaN(NaN), "NaN = " + NaN);
o = undefined;
undefined = 1;
ok(undefined === o, "NaN = " + NaN);
o = Infinity;
Infinity = 1;
ok(Infinity === o, "Infinity = " + NaN);
next_test();
}
var tests = [ var tests = [
test_date_now, test_date_now,
test_toISOString, test_toISOString,
@ -291,5 +308,6 @@ var tests = [
test_isArray, test_isArray,
test_identifier_keywords, test_identifier_keywords,
test_getOwnPropertyDescriptor, test_getOwnPropertyDescriptor,
test_defineProperty test_defineProperty,
test_global_properties
]; ];