jscript: Throw proper error when invoking non-method builtin.

Instead of crashing.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2022-04-11 18:58:52 +03:00 committed by Alexandre Julliard
parent 45d8af4cf3
commit fa09e3f36c
3 changed files with 18 additions and 0 deletions

View file

@ -560,6 +560,9 @@ static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t
case PROP_BUILTIN: {
jsval_t vthis;
if(!prop->u.p->invoke)
return JS_E_FUNCTION_EXPECTED;
if(flags == DISPATCH_CONSTRUCT && (prop->flags & PROPF_METHOD)) {
WARN("%s is not a constructor\n", debugstr_w(prop->name));
return E_INVALIDARG;

View file

@ -2611,6 +2611,8 @@ testException(function() {delete false;}, "E_INVALID_DELETE");
testException(function() {undefined.toString();}, "E_OBJECT_EXPECTED");
testException(function() {null.toString();}, "E_OBJECT_EXPECTED");
testException(function() {RegExp.prototype.toString.call(new Object());}, "E_REGEXP_EXPECTED");
testException(function() {/a/.lastIndex();}, "E_NOT_FUNC");
testException(function() {"a".length();}, "E_NOT_FUNC");
testException(function() { return arguments.callee(); }, "E_STACK_OVERFLOW");

View file

@ -1307,6 +1307,19 @@ sync_test("builtins_diffs", function() {
}catch(e) {
ok(e.number === 0xa1398 - 0x80000000, "RegExp.toString with non-regexp: exception = " + e.number);
}
try {
/a/.lastIndex();
ok(false, "/a/.lastIndex(): expected exception");
}catch(e) {
ok(e.number === 0xa138a - 0x80000000, "/a/.lastIndex(): exception = " + e.number);
}
try {
"a".length();
ok(false, "\"a\".length(): expected exception");
}catch(e) {
ok(e.number === 0xa138a - 0x80000000, "\"a\".length(): exception = " + e.number);
}
});
sync_test("__proto__", function() {