LibJS: Use a premade shape for normal function object prototypes
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This avoids one shape allocation per function instantiation.
This commit is contained in:
Andreas Kling 2025-03-25 19:16:11 +00:00 committed by Jelle Raaijmakers
parent dba1798de7
commit 8af5f25dd0
Notes: github-actions[bot] 2025-03-27 15:01:47 +00:00
3 changed files with 14 additions and 2 deletions

View file

@ -354,8 +354,8 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
Object* prototype = nullptr;
switch (m_kind) {
case FunctionKind::Normal:
prototype = Object::create_prototype(realm, realm.intrinsics().object_prototype());
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
prototype = Object::create_with_premade_shape(realm.intrinsics().normal_function_prototype_shape());
prototype->put_direct(realm.intrinsics().normal_function_prototype_constructor_offset(), this);
break;
case FunctionKind::Generator:
// prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)