Skip to content

Commit 59ce6c9

Browse files
committed
LibJS: Shrink two u64 fields in ExecutionContext to u32
To shrink ExecutionContext, these two fields are made 32-bit: - skip_when_determining_incumbent_counter - program_counter
1 parent 4c7ffc0 commit 59ce6c9

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

Libraries/LibJS/Bytecode/Interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
305305
return js_undefined();
306306
}
307307

308-
NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception(size_t& program_counter, Value exception)
308+
NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception(u32& program_counter, Value exception)
309309
{
310310
reg(Register::exception()) = exception;
311311
m_scheduled_jump = {};
@@ -349,7 +349,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
349349
auto& executable = current_executable();
350350
auto const* bytecode = executable.bytecode.data();
351351

352-
size_t& program_counter = running_execution_context.program_counter;
352+
u32& program_counter = running_execution_context.program_counter;
353353
program_counter = entry_point;
354354

355355
// Declare a lookup table for computed goto with each of the `handle_*` labels

Libraries/LibJS/Bytecode/Interpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class JS_API Interpreter {
9595
ExitFromExecutable,
9696
ContinueInThisExecutable,
9797
};
98-
[[nodiscard]] HandleExceptionResponse handle_exception(size_t& program_counter, Value exception);
98+
[[nodiscard]] HandleExceptionResponse handle_exception(u32& program_counter, Value exception);
9999

100100
VM& m_vm;
101101
Optional<size_t> m_scheduled_jump;

Libraries/LibJS/Runtime/ExecutionContext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ struct JS_API ExecutionContext {
5858
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
5959
GC::Ptr<Cell> context_owner;
6060

61-
size_t program_counter { 0 };
61+
u32 program_counter { 0 };
62+
63+
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
64+
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
65+
u32 skip_when_determining_incumbent_counter { 0 };
6266

6367
mutable RefPtr<CachedSourceRange> cached_source_range;
6468

6569
Optional<Value> this_value;
6670

6771
GC::Ptr<Bytecode::Executable> executable;
6872

69-
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
70-
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
71-
size_t skip_when_determining_incumbent_counter { 0 };
72-
7373
Span<Value> registers_and_constants_and_locals_and_arguments_span()
7474
{
7575
return { registers_and_constants_and_locals_and_arguments(), registers_and_constants_and_locals_and_arguments_count };

Libraries/LibWeb/HTML/Scripting/Environments.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ void prepare_to_run_callback(JS::Realm& realm)
207207
auto* context = top_most_script_having_execution_context(vm);
208208

209209
// 3. If context is not null, increment context's skip-when-determining-incumbent counter.
210-
if (context)
210+
if (context) {
211211
context->skip_when_determining_incumbent_counter++;
212+
}
212213
}
213214

214215
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url
@@ -265,8 +266,9 @@ void clean_up_after_running_callback(JS::Realm const& realm)
265266
auto* context = top_most_script_having_execution_context(vm);
266267

267268
// 2. If context is not null, decrement context's skip-when-determining-incumbent counter.
268-
if (context)
269+
if (context) {
269270
context->skip_when_determining_incumbent_counter--;
271+
}
270272

271273
// 3. Assert: the topmost entry of the backup incumbent realm stack is realm.
272274
auto& event_loop = HTML::main_thread_event_loop();

0 commit comments

Comments
 (0)