Commit graph

1831 commits

Author SHA1 Message Date
Gabriel Ivăncescu 954dd16fb1 jscript: Use the object containing the prop for builtin getters.
Since they act like values.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-08-01 21:51:13 +09:00
Gabriel Ivăncescu 1b1d09724a jscript: Call the getter with the proper 'this' in invoke_prop_func.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-08-01 21:51:13 +09:00
Gabriel Ivăncescu 3ab9a1da45 jscript: Properly set JS_E_WRONG_THIS as a TypeError.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:40 +02:00
Gabriel Ivăncescu 1b14d7b46d jscript: Implement WeakMap.has().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu 6a22b304b2 jscript: Implement WeakMap.clear().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu 56c74e381b jscript: Implement WeakMap.delete().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu bc1b8b277a jscript: Implement WeakMap.get().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu b4373a9e18 jscript: Implement WeakMap.set().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu b8dbee6916 jscript: Implement WeakMap instance stub and constructor.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Gabriel Ivăncescu 3f20b8aa3e jscript: Convert unlink_props to a helper that unlinks the entire object.
It will be useful for other cases, and we don't need the gc_ctx for
unlinking. Also set the PROP_PROTREFs to PROP_DELETED since we're unliking
the prototype.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-07-20 21:48:39 +02:00
Alistair Leslie-Hughes 803834fddf jscript: Remove DECLSPEC_HIDDEN usage. 2023-07-03 22:15:42 +02:00
Gabriel Ivăncescu 38f6eb34b8 jscript: Properly handle passing undefined value to Number.toString in ES5+ mode.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 3d04d052cd jscript: Properly handle passing undefined value to Number.toPrecision.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 1f4cdeeeac jscript: Always create detached variable objects with no class.
As it is done in exec_source. This matters as we actually have a check in
exprval_call that relies on this (because scope variable objects must never
be exposed).

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 4a78b9914f jscript: Don't use detached arguments buffer in html mode.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 963be08bcc jscript: Store ref to scope directly instead of frame in arguments object.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 898b705e83 jscript: Don't expose Function.prototype.arguments in non-html mode.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu a4c2f6ab72 jscript: Throw error when accessing arguments prop of bind functions.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 426f4bb3ea jscript: Implement caller for function instances and prototype.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu e748ead5cf jscript: Use jsstr_empty instead of allocating empty string.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-23 22:48:18 +02:00
Gabriel Ivăncescu 88903fa674 jscript: Get rid of the function instance in arguments obj.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:51 +02:00
Gabriel Ivăncescu 59372aa98c jscript: Start from the last argument when adding them to named locals.
This is needed for duplicated argument names, as the last arg will shadow
all the prior ones when it comes to name lookup.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:49 +02:00
Gabriel Ivăncescu 1b385fa37c jscript: Store detached args into a scope's specialized buffer.
Rather than using the variable obj for it. Since it's an implementation
detail, the scope's dispex object accesses them using index props (using
same indices as the buffer's).

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:45 +02:00
Gabriel Ivăncescu e72e8f3ab4 jscript: Don't use iface_to_jsdisp where it's not necessary to grab it.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:45 +02:00
Gabriel Ivăncescu 0e9d221582 jscript: Get rid of jsobj in scope_chain_t.
It was confusing and aliased to obj when it was a jsdisp (and shared ref), but
we can obtain that already with helpers as needed (as_jsdisp and to_jsdisp),
no reason to keep it so confusing and a separate field.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:41 +02:00
Gabriel Ivăncescu 08e0ebee49 jscript: Fix function leak in scope_init_locals.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:41 +02:00
Gabriel Ivăncescu 2173cac68e jscript: Fix addressing invalid memory if ref is an argument.
`ref` can be negative in case it refers to an argument. Even though scope !=
frame->base_scope would rule this out (because only base scopes have args),
it was checked *after* the memory access, which would read out of bounds
memory first. This didn't appear as an issue in practice since it's using the
heap pool, so there's probably valid memory before it, but it's still wrong.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:39 +02:00
Gabriel Ivăncescu a184ace43d jscript: Correctly implement context for indirect eval calls in ES5+ modes.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-06-21 18:54:39 +02:00
Alex Henrie b9aaaacc16 jscript: Fix memory leak on error path in regexp_string_match (scan-build). 2023-06-07 22:48:27 +02:00
Alex Henrie 01deef2211 jscript: Remove unnecessary call to malloc in strbuf_ensure_size. 2023-06-05 14:01:07 +02:00
Alex Henrie 66929987ab jscript: Fix memory leak on error path in String_replace (scan-build). 2023-06-05 14:01:07 +02:00
Gabriel Ivăncescu c0e8f1669f jscript: Throw proper error for out of memory conditions in RegExp.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-05-30 16:42:12 +02:00
Gabriel Ivăncescu e7b06b0ddd jscript: Throw proper error for unexpected quantifiers in RegExp.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-05-30 16:42:12 +02:00
Gabriel Ivăncescu 627e5b3bf1 jscript: Return undefined for empty RegExp captures in ES5+ mode.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-05-30 13:46:18 +02:00
Michael Stefaniuc 8d142cb106 jscript: Use separate statements instead of the comma operator. 2023-03-30 18:49:23 +02:00
Gabriel Ivăncescu 5ddeae6ac1 jscript: Fix jsstr leak after changing variant type to BSTR.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-03-13 22:07:14 +01:00
Gabriel Ivăncescu c2b5538711 jscript: Pass the correct ServiceProvider when invoking external prop.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-02-01 22:29:43 +01:00
Gabriel Ivăncescu 6deee88a6c jscript: Implement SID_GetCaller for QueryService.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2023-01-27 13:39:06 +01:00
Gabriel Ivăncescu aa7f3b1ef6 jscript: Fix JSCaller Release refcount.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-20 22:39:25 +01:00
Gabriel Ivăncescu b77255f88b jscript: Fix refcount trace's long type format specifier.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-15 18:30:38 +01:00
Gabriel Ivăncescu d1f176b497 jscript: Fix array ref leak when setting element.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-15 18:30:38 +01:00
Gabriel Ivăncescu 2ecf699dca jscript: Release converted args after invoking.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-15 18:30:38 +01:00
Gabriel Ivăncescu 27ceb62ebd jscript: Create the source function's 'prototype' prop object on demand.
The 'prototype' prop of a source function is, by default, an empty object with
a 'constructor' prop pointing back to the function. Currently, every source
function is created in this fashion, which makes it a circular reference
and thus prevents it from being freed until the Garbage Collector kicks in.

The performance impact comes from the function keeping a ref to the
enclosing scope, and since the scope is being held by it, the engine will
detach the scope, believing it to be used for the time being (until the
GC cleans it). This can cause substantial performance issues for such a
common case. The FFXIV Launcher, for example, leaks a large amount of such
short-lived functions and the enclosing scopes.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-08 20:32:10 +01:00
Gabriel Ivăncescu d192aa102f jscript: Run the garbage collector every 30 seconds on a new object allocation.
Better heuristics can be used in the future.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-08 20:32:10 +01:00
Gabriel Ivăncescu 809a91b82f jscript: Implement CollectGarbage().
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-08 20:32:10 +01:00
Gabriel Ivăncescu e8ee6ddae8 jscript: Implement a Garbage Collector to deal with circular references.
Implement a basic GC based on the mark-and-sweep algorithm, without requiring
manually specifying "roots", which vastly simplifies the code.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-08 20:32:10 +01:00
Gabriel Ivăncescu b0db79d769 jscript: Use a jsdisp to hold refs for scopes.
So the garbage collector can traverse it.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-12-08 20:32:10 +01:00
Gabriel Ivăncescu 2e4721ac8f jscript: Pass correct 'this' to host objects in ES5 mode.
For some reason, only pure js objects are passed in mshtml's jscript engine.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-11-30 20:48:20 +01:00
Gabriel Ivăncescu 534b977c62 jscript: Throw proper error when calling Set constructor as method.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-11-23 17:59:47 +01:00
Gabriel Ivăncescu 84f7f60192 jscript: Throw proper error when calling Map constructor as method.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
2022-11-23 17:59:47 +01:00