mirror of
https://gitlab.winehq.org/wine/wine.git
synced 2024-11-19 17:06:04 -07:00
jscript: Make most builtin global objects configurable.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
This commit is contained in:
parent
10cf578898
commit
c4630993fb
Notes:
Alexandre Julliard
2024-11-18 23:19:10 +01:00
Approved-by: Jacek Caban (@jacek) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/wine/merge_requests/6678
3 changed files with 114 additions and 25 deletions
|
@ -943,7 +943,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Function", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Function", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->function_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -952,7 +952,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Object", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Object", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->object_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -961,7 +961,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Array", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Array", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->array_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -970,7 +970,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Boolean", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Boolean", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->bool_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -979,7 +979,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Date", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Date", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->date_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -988,7 +988,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Enumerator", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Enumerator", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->enumerator_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -997,42 +997,42 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Error", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Error", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"EvalError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"EvalError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->eval_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RangeError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RangeError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->range_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"ReferenceError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"ReferenceError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->reference_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RegExpError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RegExpError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->regexp_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"SyntaxError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"SyntaxError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->syntax_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"TypeError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"TypeError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->type_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"URIError", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"URIError", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->uri_error_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1041,7 +1041,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Number", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Number", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->number_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1050,7 +1050,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RegExp", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"RegExp", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->regexp_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1059,7 +1059,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"String", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"String", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->string_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1068,7 +1068,7 @@ static HRESULT init_constructors(script_ctx_t *ctx, jsdisp_t *object_prototype)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"VBArray", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"VBArray", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(ctx->vbarray_constr));
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1105,7 +1105,7 @@ HRESULT init_global(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Math", PROPF_WRITABLE, jsval_obj(math));
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Math", PROPF_CONFIGURABLE | PROPF_WRITABLE, jsval_obj(math));
|
||||
jsdisp_release(math);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1117,7 +1117,7 @@ HRESULT init_global(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"JSON", PROPF_WRITABLE, jsval_obj(json));
|
||||
hres = jsdisp_define_data_property(ctx->global, L"JSON", PROPF_CONFIGURABLE | PROPF_WRITABLE, jsval_obj(json));
|
||||
jsdisp_release(json);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
@ -1127,7 +1127,7 @@ HRESULT init_global(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"ActiveXObject", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"ActiveXObject", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(constr));
|
||||
jsdisp_release(constr);
|
||||
if(FAILED(hres))
|
||||
|
|
|
@ -903,7 +903,7 @@ HRESULT init_set_constructor(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Set", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Set", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(constructor));
|
||||
jsdisp_release(constructor);
|
||||
if(FAILED(hres))
|
||||
|
@ -918,7 +918,7 @@ HRESULT init_set_constructor(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Map", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"Map", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(constructor));
|
||||
jsdisp_release(constructor);
|
||||
if(FAILED(hres))
|
||||
|
@ -933,7 +933,7 @@ HRESULT init_set_constructor(script_ctx_t *ctx)
|
|||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
hres = jsdisp_define_data_property(ctx->global, L"WeakMap", PROPF_WRITABLE,
|
||||
hres = jsdisp_define_data_property(ctx->global, L"WeakMap", PROPF_CONFIGURABLE | PROPF_WRITABLE,
|
||||
jsval_obj(constructor));
|
||||
jsdisp_release(constructor);
|
||||
return hres;
|
||||
|
|
|
@ -23,6 +23,7 @@ var JS_E_NUMBER_EXPECTED = 0x800a1389;
|
|||
var JS_E_FUNCTION_EXPECTED = 0x800a138a;
|
||||
var JS_E_DATE_EXPECTED = 0x800a138e;
|
||||
var JS_E_OBJECT_EXPECTED = 0x800a138f;
|
||||
var JS_E_UNDEFINED_VARIABLE = 0x800a1391;
|
||||
var JS_E_BOOLEAN_EXPECTED = 0x800a1392;
|
||||
var JS_E_VBARRAY_EXPECTED = 0x800a1395;
|
||||
var JS_E_ENUMERATOR_EXPECTED = 0x800a1397;
|
||||
|
@ -2159,7 +2160,7 @@ sync_test("globals override", function() {
|
|||
ok(window.wineprop === 1337, "window.wineprop = " + window.wineprop);
|
||||
ok(wineprop === 1337, "wineprop = " + wineprop);
|
||||
|
||||
var r = Object.defineProperty(window, "wineprop", { value: 42, configurable: true });
|
||||
var i, desc, r = Object.defineProperty(window, "wineprop", { value: 42, configurable: true });
|
||||
ok(r === window, "defineProperty(window.wineprop) returned " + r);
|
||||
ok(window.hasOwnProperty("wineprop"), "wineprop not a prop of window after override");
|
||||
ok(window.wineprop === 42, "window.wineprop after override = " + window.wineprop);
|
||||
|
@ -2168,6 +2169,94 @@ sync_test("globals override", function() {
|
|||
r = (delete window.wineprop);
|
||||
ok(r === true, "delete window.wineprop returned " + r);
|
||||
ok(!("wineprop" in window), "wineprop in window after delete");
|
||||
|
||||
/* configurable */
|
||||
var builtins = [
|
||||
"ActiveXObject",
|
||||
"Array",
|
||||
"ArrayBuffer",
|
||||
"Boolean",
|
||||
"CollectGarbage",
|
||||
"DataView",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"Enumerator",
|
||||
"Error",
|
||||
"escape",
|
||||
"EvalError",
|
||||
"Function",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"Number",
|
||||
"parseFloat",
|
||||
"parseInt",
|
||||
"RangeError",
|
||||
"ReferenceError",
|
||||
"RegExp",
|
||||
"ScriptEngine",
|
||||
"ScriptEngineBuildVersion",
|
||||
"ScriptEngineMajorVersion",
|
||||
"ScriptEngineMinorVersion",
|
||||
"Set",
|
||||
"String",
|
||||
"SyntaxError",
|
||||
"TypeError",
|
||||
"unescape",
|
||||
"URIError",
|
||||
"VBArray",
|
||||
"WeakMap"
|
||||
];
|
||||
for(i = 0; i < builtins.length; i++) {
|
||||
desc = Object.getOwnPropertyDescriptor(window, builtins[i]);
|
||||
ok(desc !== undefined, "getOwnPropertyDescriptor('" + builtins[i] + "' returned undefined");
|
||||
ok(desc.configurable === true, builtins[i] + " not configurable");
|
||||
ok(desc.enumerable === false, builtins[i] + " is enumerable");
|
||||
ok(desc.writable === true, builtins[i] + " not writable");
|
||||
|
||||
r = Object.defineProperty(window, builtins[i], { value: 12, configurable: true, writable: true });
|
||||
ok(r === window, "defineProperty('" + builtins[i] + "' returned " + r);
|
||||
r = Object.getOwnPropertyDescriptor(window, builtins[i]);
|
||||
ok(r !== undefined, "getOwnPropertyDescriptor('" + builtins[i] + "' after override returned undefined");
|
||||
ok(r.value === 12, builtins[i] + " value = " + r.value);
|
||||
|
||||
r = eval(builtins[i]);
|
||||
ok(r === window[builtins[i]], "Global " + builtins[i] + " does not match redefined window." + builtins[i]);
|
||||
r = (delete window[builtins[i]]);
|
||||
ok(r === true, "delete window." + builtins[i] + " returned " + r);
|
||||
ok(!(builtins[i] in window), builtins[i] + " in window after delete");
|
||||
try {
|
||||
eval(builtins[i]);
|
||||
ok(false, "expected exception retrieving global " + builtins[i] + " after delete.");
|
||||
}catch(ex) {
|
||||
r = ex.number >>> 0;
|
||||
ok(r === JS_E_UNDEFINED_VARIABLE, "retrieving global " + builtins[i] + " after delete threw " + r);
|
||||
}
|
||||
|
||||
r = Object.defineProperty(window, builtins[i], desc);
|
||||
ok(r === window, "defineProperty('" + builtins[i] + "' to restore returned " + r);
|
||||
}
|
||||
|
||||
/* non-configurable */
|
||||
builtins = [
|
||||
"undefined",
|
||||
"Infinity",
|
||||
"NaN"
|
||||
];
|
||||
for(i = 0; i < builtins.length; i++) {
|
||||
desc = Object.getOwnPropertyDescriptor(window, builtins[i]);
|
||||
ok(desc !== undefined, "getOwnPropertyDescriptor('" + builtins[i] + "' returned undefined");
|
||||
todo_wine.
|
||||
ok(desc.configurable === false, builtins[i] + " is configurable");
|
||||
ok(desc.enumerable === false, builtins[i] + " is enumerable");
|
||||
todo_wine.
|
||||
ok(desc.writable === false, builtins[i] + " is writable");
|
||||
}
|
||||
});
|
||||
|
||||
sync_test("host this", function() {
|
||||
|
|
Loading…
Reference in a new issue