Skip to content

Commit caf2e67

Browse files
awesomeklingkalenikaliaksandr
authored andcommitted
LibJS/Bytecode: Don't emit GetGlobal undefined
We know that `undefined` in the global scope is always the proper undefined value. This commit takes advantage of that by simply emitting a constant undefined value instead. Unfortunately we can't be so sure in other scopes.
1 parent 448f837 commit caf2e67

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> Identifier::generate_by
382382
return local;
383383
}
384384

385+
if (is_global() && m_string == "undefined"sv) {
386+
return generator.add_constant(js_undefined());
387+
}
388+
385389
auto dst = choose_dst(generator, preferred_dst);
386390
if (is_global()) {
387391
generator.emit<Bytecode::Op::GetGlobal>(dst, generator.intern_identifier(m_string), generator.next_global_variable_cache());

0 commit comments

Comments
 (0)