Interpreter.cpp 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566
  1. /*
  2. * Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Debug.h>
  7. #include <AK/HashTable.h>
  8. #include <AK/TemporaryChange.h>
  9. #include <LibJS/AST.h>
  10. #include <LibJS/Bytecode/BasicBlock.h>
  11. #include <LibJS/Bytecode/CommonImplementations.h>
  12. #include <LibJS/Bytecode/Generator.h>
  13. #include <LibJS/Bytecode/Instruction.h>
  14. #include <LibJS/Bytecode/Interpreter.h>
  15. #include <LibJS/Bytecode/Label.h>
  16. #include <LibJS/Bytecode/Op.h>
  17. #include <LibJS/Runtime/AbstractOperations.h>
  18. #include <LibJS/Runtime/Array.h>
  19. #include <LibJS/Runtime/BigInt.h>
  20. #include <LibJS/Runtime/DeclarativeEnvironment.h>
  21. #include <LibJS/Runtime/ECMAScriptFunctionObject.h>
  22. #include <LibJS/Runtime/Environment.h>
  23. #include <LibJS/Runtime/FunctionEnvironment.h>
  24. #include <LibJS/Runtime/GlobalEnvironment.h>
  25. #include <LibJS/Runtime/GlobalObject.h>
  26. #include <LibJS/Runtime/Iterator.h>
  27. #include <LibJS/Runtime/MathObject.h>
  28. #include <LibJS/Runtime/NativeFunction.h>
  29. #include <LibJS/Runtime/ObjectEnvironment.h>
  30. #include <LibJS/Runtime/Realm.h>
  31. #include <LibJS/Runtime/Reference.h>
  32. #include <LibJS/Runtime/RegExpObject.h>
  33. #include <LibJS/Runtime/Value.h>
  34. #include <LibJS/Runtime/ValueInlines.h>
  35. #include <LibJS/SourceTextModule.h>
  36. namespace JS::Bytecode {
  37. bool g_dump_bytecode = false;
  38. static ByteString format_operand(StringView name, Operand operand, Bytecode::Executable const& executable)
  39. {
  40. StringBuilder builder;
  41. if (!name.is_empty())
  42. builder.appendff("\033[32m{}\033[0m:", name);
  43. switch (operand.type()) {
  44. case Operand::Type::Register:
  45. builder.appendff("\033[33mreg{}\033[0m", operand.index());
  46. break;
  47. case Operand::Type::Local:
  48. // FIXME: Show local name.
  49. builder.appendff("\033[34mloc{}\033[0m", operand.index());
  50. break;
  51. case Operand::Type::Constant: {
  52. builder.append("\033[36m"sv);
  53. auto value = executable.constants[operand.index()];
  54. if (value.is_empty())
  55. builder.append("<Empty>"sv);
  56. else if (value.is_boolean())
  57. builder.appendff("Bool({})", value.as_bool() ? "true"sv : "false"sv);
  58. else if (value.is_int32())
  59. builder.appendff("Int32({})", value.as_i32());
  60. else if (value.is_double())
  61. builder.appendff("Double({})", value.as_double());
  62. else if (value.is_bigint())
  63. builder.appendff("BigInt({})", value.as_bigint().to_byte_string());
  64. else if (value.is_string())
  65. builder.appendff("String(\"{}\")", value.as_string().utf8_string_view());
  66. else if (value.is_undefined())
  67. builder.append("Undefined"sv);
  68. else if (value.is_null())
  69. builder.append("Null"sv);
  70. else
  71. builder.appendff("Value: {}", value);
  72. builder.append("\033[0m"sv);
  73. break;
  74. }
  75. default:
  76. VERIFY_NOT_REACHED();
  77. }
  78. return builder.to_byte_string();
  79. }
  80. static ByteString format_operand_list(StringView name, ReadonlySpan<Operand> operands, Bytecode::Executable const& executable)
  81. {
  82. StringBuilder builder;
  83. if (!name.is_empty())
  84. builder.appendff("\033[32m{}\033[0m:[", name);
  85. for (size_t i = 0; i < operands.size(); ++i) {
  86. if (i != 0)
  87. builder.append(", "sv);
  88. builder.appendff("{}", format_operand(""sv, operands[i], executable));
  89. }
  90. builder.append("]"sv);
  91. return builder.to_byte_string();
  92. }
  93. static ByteString format_value_list(StringView name, ReadonlySpan<Value> values)
  94. {
  95. StringBuilder builder;
  96. if (!name.is_empty())
  97. builder.appendff("\033[32m{}\033[0m:[", name);
  98. builder.join(", "sv, values);
  99. builder.append("]"sv);
  100. return builder.to_byte_string();
  101. }
  102. ALWAYS_INLINE static ThrowCompletionOr<Value> loosely_inequals(VM& vm, Value src1, Value src2)
  103. {
  104. if (src1.tag() == src2.tag()) {
  105. if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
  106. return Value(src1.encoded() != src2.encoded());
  107. }
  108. return Value(!TRY(is_loosely_equal(vm, src1, src2)));
  109. }
  110. ALWAYS_INLINE static ThrowCompletionOr<Value> loosely_equals(VM& vm, Value src1, Value src2)
  111. {
  112. if (src1.tag() == src2.tag()) {
  113. if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
  114. return Value(src1.encoded() == src2.encoded());
  115. }
  116. return Value(TRY(is_loosely_equal(vm, src1, src2)));
  117. }
  118. ALWAYS_INLINE static ThrowCompletionOr<Value> strict_inequals(VM&, Value src1, Value src2)
  119. {
  120. if (src1.tag() == src2.tag()) {
  121. if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
  122. return Value(src1.encoded() != src2.encoded());
  123. }
  124. return Value(!is_strictly_equal(src1, src2));
  125. }
  126. ALWAYS_INLINE static ThrowCompletionOr<Value> strict_equals(VM&, Value src1, Value src2)
  127. {
  128. if (src1.tag() == src2.tag()) {
  129. if (src1.is_int32() || src1.is_object() || src1.is_boolean() || src1.is_nullish())
  130. return Value(src1.encoded() == src2.encoded());
  131. }
  132. return Value(is_strictly_equal(src1, src2));
  133. }
  134. Interpreter::Interpreter(VM& vm)
  135. : m_vm(vm)
  136. {
  137. }
  138. Interpreter::~Interpreter()
  139. {
  140. }
  141. ALWAYS_INLINE Value Interpreter::get(Operand op) const
  142. {
  143. switch (op.type()) {
  144. case Operand::Type::Register:
  145. return reg(Register { op.index() });
  146. case Operand::Type::Local:
  147. return m_locals.data()[op.index()];
  148. case Operand::Type::Constant:
  149. return current_executable().constants[op.index()];
  150. }
  151. __builtin_unreachable();
  152. }
  153. ALWAYS_INLINE void Interpreter::set(Operand op, Value value)
  154. {
  155. switch (op.type()) {
  156. case Operand::Type::Register:
  157. reg(Register { op.index() }) = value;
  158. return;
  159. case Operand::Type::Local:
  160. m_locals.data()[op.index()] = value;
  161. return;
  162. case Operand::Type::Constant:
  163. VERIFY_NOT_REACHED();
  164. }
  165. __builtin_unreachable();
  166. }
  167. // 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
  168. ThrowCompletionOr<Value> Interpreter::run(Script& script_record, JS::GCPtr<Environment> lexical_environment_override)
  169. {
  170. auto& vm = this->vm();
  171. // 1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]].
  172. auto& global_environment = script_record.realm().global_environment();
  173. // 2. Let scriptContext be a new ECMAScript code execution context.
  174. auto script_context = ExecutionContext::create(vm.heap());
  175. // 3. Set the Function of scriptContext to null.
  176. // NOTE: This was done during execution context construction.
  177. // 4. Set the Realm of scriptContext to scriptRecord.[[Realm]].
  178. script_context->realm = &script_record.realm();
  179. // 5. Set the ScriptOrModule of scriptContext to scriptRecord.
  180. script_context->script_or_module = NonnullGCPtr<Script>(script_record);
  181. // 6. Set the VariableEnvironment of scriptContext to globalEnv.
  182. script_context->variable_environment = &global_environment;
  183. // 7. Set the LexicalEnvironment of scriptContext to globalEnv.
  184. script_context->lexical_environment = &global_environment;
  185. // Non-standard: Override the lexical environment if requested.
  186. if (lexical_environment_override)
  187. script_context->lexical_environment = lexical_environment_override;
  188. // 8. Set the PrivateEnvironment of scriptContext to null.
  189. // NOTE: This isn't in the spec, but we require it.
  190. script_context->is_strict_mode = script_record.parse_node().is_strict_mode();
  191. // FIXME: 9. Suspend the currently running execution context.
  192. // 10. Push scriptContext onto the execution context stack; scriptContext is now the running execution context.
  193. TRY(vm.push_execution_context(*script_context, {}));
  194. // 11. Let script be scriptRecord.[[ECMAScriptCode]].
  195. auto& script = script_record.parse_node();
  196. // 12. Let result be Completion(GlobalDeclarationInstantiation(script, globalEnv)).
  197. auto instantiation_result = script.global_declaration_instantiation(vm, global_environment);
  198. Completion result = instantiation_result.is_throw_completion() ? instantiation_result.throw_completion() : normal_completion({});
  199. // 13. If result.[[Type]] is normal, then
  200. if (result.type() == Completion::Type::Normal) {
  201. auto executable_result = JS::Bytecode::Generator::generate(vm, script, {});
  202. if (executable_result.is_error()) {
  203. if (auto error_string = executable_result.error().to_string(); error_string.is_error())
  204. result = vm.template throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory));
  205. else if (error_string = String::formatted("TODO({})", error_string.value()); error_string.is_error())
  206. result = vm.template throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory));
  207. else
  208. result = JS::throw_completion(JS::InternalError::create(realm(), error_string.release_value()));
  209. } else {
  210. auto executable = executable_result.release_value();
  211. if (g_dump_bytecode)
  212. executable->dump();
  213. // a. Set result to the result of evaluating script.
  214. auto result_or_error = run_executable(*executable, {}, {});
  215. if (result_or_error.value.is_error())
  216. result = result_or_error.value.release_error();
  217. else
  218. result = result_or_error.return_register_value;
  219. }
  220. }
  221. // 14. If result.[[Type]] is normal and result.[[Value]] is empty, then
  222. if (result.type() == Completion::Type::Normal && !result.value().has_value()) {
  223. // a. Set result to NormalCompletion(undefined).
  224. result = normal_completion(js_undefined());
  225. }
  226. // FIXME: 15. Suspend scriptContext and remove it from the execution context stack.
  227. vm.pop_execution_context();
  228. // 16. Assert: The execution context stack is not empty.
  229. VERIFY(!vm.execution_context_stack().is_empty());
  230. // FIXME: 17. Resume the context that is now on the top of the execution context stack as the running execution context.
  231. // At this point we may have already run any queued promise jobs via on_call_stack_emptied,
  232. // in which case this is a no-op.
  233. // FIXME: These three should be moved out of Interpreter::run and give the host an option to run these, as it's up to the host when these get run.
  234. // https://tc39.es/ecma262/#sec-jobs for jobs and https://tc39.es/ecma262/#_ref_3508 for ClearKeptObjects
  235. // finish_execution_generation is particularly an issue for LibWeb, as the HTML spec wants to run it specifically after performing a microtask checkpoint.
  236. // The promise and registry cleanup queues don't cause LibWeb an issue, as LibWeb overrides the hooks that push onto these queues.
  237. vm.run_queued_promise_jobs();
  238. vm.run_queued_finalization_registry_cleanup_jobs();
  239. vm.finish_execution_generation();
  240. // 18. Return ? result.
  241. if (result.is_abrupt()) {
  242. VERIFY(result.type() == Completion::Type::Throw);
  243. return result.release_error();
  244. }
  245. VERIFY(result.value().has_value());
  246. return *result.value();
  247. }
  248. ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
  249. {
  250. // FIXME: This is not a entry point as defined in the spec, but is convenient.
  251. // To avoid work we use link_and_eval_module however that can already be
  252. // dangerous if the vm loaded other modules.
  253. auto& vm = this->vm();
  254. TRY(vm.link_and_eval_module(Badge<Bytecode::Interpreter> {}, module));
  255. vm.run_queued_promise_jobs();
  256. vm.run_queued_finalization_registry_cleanup_jobs();
  257. return js_undefined();
  258. }
  259. Interpreter::HandleExceptionResponse Interpreter::handle_exception(size_t& program_counter, Value exception)
  260. {
  261. reg(Register::exception()) = exception;
  262. m_scheduled_jump = {};
  263. auto handlers = current_executable().exception_handlers_for_offset(program_counter);
  264. if (!handlers.has_value()) {
  265. return HandleExceptionResponse::ExitFromExecutable;
  266. }
  267. auto& handler = handlers->handler_offset;
  268. auto& finalizer = handlers->finalizer_offset;
  269. VERIFY(!vm().running_execution_context().unwind_contexts.is_empty());
  270. auto& unwind_context = vm().running_execution_context().unwind_contexts.last();
  271. VERIFY(unwind_context.executable == m_current_executable);
  272. if (handler.has_value()) {
  273. program_counter = handler.value();
  274. return HandleExceptionResponse::ContinueInThisExecutable;
  275. }
  276. if (finalizer.has_value()) {
  277. program_counter = finalizer.value();
  278. return HandleExceptionResponse::ContinueInThisExecutable;
  279. }
  280. VERIFY_NOT_REACHED();
  281. }
  282. // FIXME: GCC takes a *long* time to compile with flattening, and it will time out our CI. :|
  283. #if defined(AK_COMPILER_CLANG)
  284. # define FLATTEN_ON_CLANG FLATTEN
  285. #else
  286. # define FLATTEN_ON_CLANG
  287. #endif
  288. FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
  289. {
  290. if (vm().did_reach_stack_space_limit()) {
  291. reg(Register::exception()) = vm().throw_completion<InternalError>(ErrorType::CallStackSizeExceeded).release_value().value();
  292. return;
  293. }
  294. auto& running_execution_context = vm().running_execution_context();
  295. auto* locals = running_execution_context.locals.data();
  296. auto& accumulator = this->accumulator();
  297. auto& executable = current_executable();
  298. auto const* bytecode = executable.bytecode.data();
  299. size_t program_counter = entry_point;
  300. TemporaryChange change(m_program_counter, Optional<size_t&>(program_counter));
  301. // Declare a lookup table for computed goto with each of the `handle_*` labels
  302. // to avoid the overhead of a switch statement.
  303. // This is a GCC extension, but it's also supported by Clang.
  304. static void* const bytecode_dispatch_table[] = {
  305. #define SET_UP_LABEL(name) &&handle_##name,
  306. ENUMERATE_BYTECODE_OPS(SET_UP_LABEL)
  307. };
  308. #undef SET_UP_LABEL
  309. #define DISPATCH_NEXT(name) \
  310. do { \
  311. if constexpr (Op::name::IsVariableLength) \
  312. program_counter += instruction.length(); \
  313. else \
  314. program_counter += sizeof(Op::name); \
  315. auto& next_instruction = *reinterpret_cast<Instruction const*>(&bytecode[program_counter]); \
  316. goto* bytecode_dispatch_table[static_cast<size_t>(next_instruction.type())]; \
  317. } while (0)
  318. for (;;) {
  319. start:
  320. bool will_return = false;
  321. bool will_yield = false;
  322. for (;;) {
  323. goto* bytecode_dispatch_table[static_cast<size_t>((*reinterpret_cast<Instruction const*>(&bytecode[program_counter])).type())];
  324. handle_SetLocal: {
  325. auto& instruction = *reinterpret_cast<Op::SetLocal const*>(&bytecode[program_counter]);
  326. locals[instruction.index()] = get(instruction.src());
  327. DISPATCH_NEXT(SetLocal);
  328. }
  329. handle_Mov: {
  330. auto& instruction = *reinterpret_cast<Op::Mov const*>(&bytecode[program_counter]);
  331. set(instruction.dst(), get(instruction.src()));
  332. DISPATCH_NEXT(Mov);
  333. }
  334. handle_End: {
  335. auto& instruction = *reinterpret_cast<Op::End const*>(&bytecode[program_counter]);
  336. accumulator = get(instruction.value());
  337. return;
  338. }
  339. handle_Jump: {
  340. auto& instruction = *reinterpret_cast<Op::Jump const*>(&bytecode[program_counter]);
  341. program_counter = instruction.target().address();
  342. goto start;
  343. }
  344. handle_JumpIf: {
  345. auto& instruction = *reinterpret_cast<Op::JumpIf const*>(&bytecode[program_counter]);
  346. if (get(instruction.condition()).to_boolean())
  347. program_counter = instruction.true_target().address();
  348. else
  349. program_counter = instruction.false_target().address();
  350. goto start;
  351. }
  352. handle_JumpTrue: {
  353. auto& instruction = *reinterpret_cast<Op::JumpTrue const*>(&bytecode[program_counter]);
  354. if (get(instruction.condition()).to_boolean()) {
  355. program_counter = instruction.target().address();
  356. goto start;
  357. }
  358. DISPATCH_NEXT(JumpTrue);
  359. }
  360. handle_JumpFalse: {
  361. auto& instruction = *reinterpret_cast<Op::JumpFalse const*>(&bytecode[program_counter]);
  362. if (!get(instruction.condition()).to_boolean()) {
  363. program_counter = instruction.target().address();
  364. goto start;
  365. }
  366. DISPATCH_NEXT(JumpFalse);
  367. }
  368. handle_JumpNullish: {
  369. auto& instruction = *reinterpret_cast<Op::JumpNullish const*>(&bytecode[program_counter]);
  370. if (get(instruction.condition()).is_nullish())
  371. program_counter = instruction.true_target().address();
  372. else
  373. program_counter = instruction.false_target().address();
  374. goto start;
  375. }
  376. #define HANDLE_COMPARISON_OP(op_TitleCase, op_snake_case) \
  377. handle_Jump##op_TitleCase: \
  378. { \
  379. auto& instruction = *reinterpret_cast<Op::Jump##op_TitleCase const*>(&bytecode[program_counter]); \
  380. auto result = op_snake_case(vm(), get(instruction.lhs()), get(instruction.rhs())); \
  381. if (result.is_error()) { \
  382. if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable) \
  383. return; \
  384. goto start; \
  385. } \
  386. if (result.value().to_boolean()) \
  387. program_counter = instruction.true_target().address(); \
  388. else \
  389. program_counter = instruction.false_target().address(); \
  390. goto start; \
  391. }
  392. JS_ENUMERATE_COMPARISON_OPS(HANDLE_COMPARISON_OP)
  393. #undef HANDLE_COMPARISON_OP
  394. handle_JumpUndefined: {
  395. auto& instruction = *reinterpret_cast<Op::JumpUndefined const*>(&bytecode[program_counter]);
  396. if (get(instruction.condition()).is_undefined())
  397. program_counter = instruction.true_target().address();
  398. else
  399. program_counter = instruction.false_target().address();
  400. goto start;
  401. }
  402. handle_EnterUnwindContext: {
  403. auto& instruction = *reinterpret_cast<Op::EnterUnwindContext const*>(&bytecode[program_counter]);
  404. enter_unwind_context();
  405. program_counter = instruction.entry_point().address();
  406. goto start;
  407. }
  408. handle_ContinuePendingUnwind: {
  409. auto& instruction = *reinterpret_cast<Op::ContinuePendingUnwind const*>(&bytecode[program_counter]);
  410. if (auto exception = reg(Register::exception()); !exception.is_empty()) {
  411. if (handle_exception(program_counter, exception) == HandleExceptionResponse::ExitFromExecutable)
  412. return;
  413. goto start;
  414. }
  415. if (!saved_return_value().is_empty()) {
  416. do_return(saved_return_value());
  417. goto may_return;
  418. }
  419. auto const old_scheduled_jump = running_execution_context.previously_scheduled_jumps.take_last();
  420. if (m_scheduled_jump.has_value()) {
  421. program_counter = m_scheduled_jump.value();
  422. m_scheduled_jump = {};
  423. } else {
  424. program_counter = instruction.resume_target().address();
  425. // set the scheduled jump to the old value if we continue
  426. // where we left it
  427. m_scheduled_jump = old_scheduled_jump;
  428. }
  429. goto start;
  430. }
  431. handle_ScheduleJump: {
  432. auto& instruction = *reinterpret_cast<Op::ScheduleJump const*>(&bytecode[program_counter]);
  433. m_scheduled_jump = instruction.target().address();
  434. auto finalizer = executable.exception_handlers_for_offset(program_counter).value().finalizer_offset;
  435. VERIFY(finalizer.has_value());
  436. program_counter = finalizer.value();
  437. goto start;
  438. }
  439. #define HANDLE_INSTRUCTION(name) \
  440. handle_##name: \
  441. { \
  442. auto& instruction = *reinterpret_cast<Op::name const*>(&bytecode[program_counter]); \
  443. { \
  444. auto result = instruction.execute_impl(*this); \
  445. if (result.is_error()) { \
  446. if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable) \
  447. return; \
  448. goto start; \
  449. } \
  450. } \
  451. DISPATCH_NEXT(name); \
  452. }
  453. HANDLE_INSTRUCTION(Add);
  454. HANDLE_INSTRUCTION(ArrayAppend);
  455. HANDLE_INSTRUCTION(AsyncIteratorClose);
  456. HANDLE_INSTRUCTION(BitwiseAnd);
  457. HANDLE_INSTRUCTION(BitwiseNot);
  458. HANDLE_INSTRUCTION(BitwiseOr);
  459. HANDLE_INSTRUCTION(BitwiseXor);
  460. HANDLE_INSTRUCTION(BlockDeclarationInstantiation);
  461. HANDLE_INSTRUCTION(Call);
  462. HANDLE_INSTRUCTION(CallWithArgumentArray);
  463. HANDLE_INSTRUCTION(Catch);
  464. HANDLE_INSTRUCTION(ConcatString);
  465. HANDLE_INSTRUCTION(CopyObjectExcludingProperties);
  466. HANDLE_INSTRUCTION(CreateLexicalEnvironment);
  467. HANDLE_INSTRUCTION(CreateVariable);
  468. HANDLE_INSTRUCTION(Decrement);
  469. HANDLE_INSTRUCTION(DeleteById);
  470. HANDLE_INSTRUCTION(DeleteByIdWithThis);
  471. HANDLE_INSTRUCTION(DeleteByValue);
  472. HANDLE_INSTRUCTION(DeleteByValueWithThis);
  473. HANDLE_INSTRUCTION(DeleteVariable);
  474. HANDLE_INSTRUCTION(Div);
  475. HANDLE_INSTRUCTION(Dump);
  476. HANDLE_INSTRUCTION(EnterObjectEnvironment);
  477. HANDLE_INSTRUCTION(Exp);
  478. HANDLE_INSTRUCTION(GetById);
  479. HANDLE_INSTRUCTION(GetByIdWithThis);
  480. HANDLE_INSTRUCTION(GetByValue);
  481. HANDLE_INSTRUCTION(GetByValueWithThis);
  482. HANDLE_INSTRUCTION(GetCalleeAndThisFromEnvironment);
  483. HANDLE_INSTRUCTION(GetGlobal);
  484. HANDLE_INSTRUCTION(GetImportMeta);
  485. HANDLE_INSTRUCTION(GetIterator);
  486. HANDLE_INSTRUCTION(GetMethod);
  487. HANDLE_INSTRUCTION(GetNewTarget);
  488. HANDLE_INSTRUCTION(GetNextMethodFromIteratorRecord);
  489. HANDLE_INSTRUCTION(GetObjectFromIteratorRecord);
  490. HANDLE_INSTRUCTION(GetObjectPropertyIterator);
  491. HANDLE_INSTRUCTION(GetPrivateById);
  492. HANDLE_INSTRUCTION(GetVariable);
  493. HANDLE_INSTRUCTION(GreaterThan);
  494. HANDLE_INSTRUCTION(GreaterThanEquals);
  495. HANDLE_INSTRUCTION(HasPrivateId);
  496. HANDLE_INSTRUCTION(ImportCall);
  497. HANDLE_INSTRUCTION(In);
  498. HANDLE_INSTRUCTION(Increment);
  499. HANDLE_INSTRUCTION(InstanceOf);
  500. HANDLE_INSTRUCTION(IteratorClose);
  501. HANDLE_INSTRUCTION(IteratorNext);
  502. HANDLE_INSTRUCTION(IteratorToArray);
  503. HANDLE_INSTRUCTION(LeaveFinally);
  504. HANDLE_INSTRUCTION(LeaveLexicalEnvironment);
  505. HANDLE_INSTRUCTION(LeaveUnwindContext);
  506. HANDLE_INSTRUCTION(LeftShift);
  507. HANDLE_INSTRUCTION(LessThan);
  508. HANDLE_INSTRUCTION(LessThanEquals);
  509. HANDLE_INSTRUCTION(LooselyEquals);
  510. HANDLE_INSTRUCTION(LooselyInequals);
  511. HANDLE_INSTRUCTION(Mod);
  512. HANDLE_INSTRUCTION(Mul);
  513. HANDLE_INSTRUCTION(NewArray);
  514. HANDLE_INSTRUCTION(NewClass);
  515. HANDLE_INSTRUCTION(NewFunction);
  516. HANDLE_INSTRUCTION(NewObject);
  517. HANDLE_INSTRUCTION(NewPrimitiveArray);
  518. HANDLE_INSTRUCTION(NewRegExp);
  519. HANDLE_INSTRUCTION(NewTypeError);
  520. HANDLE_INSTRUCTION(Not);
  521. HANDLE_INSTRUCTION(PostfixDecrement);
  522. HANDLE_INSTRUCTION(PostfixIncrement);
  523. HANDLE_INSTRUCTION(PutById);
  524. HANDLE_INSTRUCTION(PutByIdWithThis);
  525. HANDLE_INSTRUCTION(PutByValue);
  526. HANDLE_INSTRUCTION(PutByValueWithThis);
  527. HANDLE_INSTRUCTION(PutPrivateById);
  528. HANDLE_INSTRUCTION(ResolveSuperBase);
  529. HANDLE_INSTRUCTION(ResolveThisBinding);
  530. HANDLE_INSTRUCTION(RestoreScheduledJump);
  531. HANDLE_INSTRUCTION(RightShift);
  532. HANDLE_INSTRUCTION(SetVariable);
  533. HANDLE_INSTRUCTION(StrictlyEquals);
  534. HANDLE_INSTRUCTION(StrictlyInequals);
  535. HANDLE_INSTRUCTION(Sub);
  536. HANDLE_INSTRUCTION(SuperCallWithArgumentArray);
  537. HANDLE_INSTRUCTION(Throw);
  538. HANDLE_INSTRUCTION(ThrowIfNotObject);
  539. HANDLE_INSTRUCTION(ThrowIfNullish);
  540. HANDLE_INSTRUCTION(ThrowIfTDZ);
  541. HANDLE_INSTRUCTION(Typeof);
  542. HANDLE_INSTRUCTION(TypeofVariable);
  543. HANDLE_INSTRUCTION(UnaryMinus);
  544. HANDLE_INSTRUCTION(UnaryPlus);
  545. HANDLE_INSTRUCTION(UnsignedRightShift);
  546. handle_Await: {
  547. auto& instruction = *reinterpret_cast<Op::Await const*>(&bytecode[program_counter]);
  548. auto result = instruction.execute(*this);
  549. if (result.is_error()) {
  550. if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable)
  551. return;
  552. goto start;
  553. }
  554. goto may_return;
  555. }
  556. handle_Return: {
  557. auto& instruction = *reinterpret_cast<Op::Return const*>(&bytecode[program_counter]);
  558. auto result = instruction.execute(*this);
  559. if (result.is_error()) {
  560. if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable)
  561. return;
  562. goto start;
  563. }
  564. goto may_return;
  565. }
  566. handle_Yield: {
  567. auto& instruction = *reinterpret_cast<Op::Yield const*>(&bytecode[program_counter]);
  568. auto result = instruction.execute(*this);
  569. if (result.is_error()) {
  570. if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable)
  571. return;
  572. goto start;
  573. }
  574. goto may_return;
  575. }
  576. may_return: {
  577. auto& instruction = *reinterpret_cast<Instruction const*>(&bytecode[program_counter]);
  578. if (!reg(Register::return_value()).is_empty()) {
  579. will_return = true;
  580. // Note: A `yield` statement will not go through a finally statement,
  581. // hence we need to set a flag to not do so,
  582. // but we generate a Yield Operation in the case of returns in
  583. // generators as well, so we need to check if it will actually
  584. // continue or is a `return` in disguise
  585. will_yield = (instruction.type() == Instruction::Type::Yield && static_cast<Op::Yield const&>(instruction).continuation().has_value()) || instruction.type() == Instruction::Type::Await;
  586. break;
  587. }
  588. program_counter += instruction.length();
  589. goto start;
  590. }
  591. }
  592. if (!will_yield) {
  593. if (auto handlers = executable.exception_handlers_for_offset(program_counter); handlers.has_value()) {
  594. if (auto finalizer = handlers.value().finalizer_offset; finalizer.has_value()) {
  595. VERIFY(!running_execution_context.unwind_contexts.is_empty());
  596. auto& unwind_context = running_execution_context.unwind_contexts.last();
  597. VERIFY(unwind_context.executable == m_current_executable);
  598. reg(Register::saved_return_value()) = reg(Register::return_value());
  599. reg(Register::return_value()) = {};
  600. program_counter = finalizer.value();
  601. // the unwind_context will be pop'ed when entering the finally block
  602. continue;
  603. }
  604. }
  605. }
  606. if (will_return)
  607. break;
  608. }
  609. }
  610. Interpreter::ResultAndReturnRegister Interpreter::run_executable(Executable& executable, Optional<size_t> entry_point, Value initial_accumulator_value)
  611. {
  612. dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run unit {:p}", &executable);
  613. TemporaryChange restore_executable { m_current_executable, GCPtr { executable } };
  614. TemporaryChange restore_saved_jump { m_scheduled_jump, Optional<size_t> {} };
  615. TemporaryChange restore_realm { m_realm, GCPtr { vm().current_realm() } };
  616. TemporaryChange restore_global_object { m_global_object, GCPtr { m_realm->global_object() } };
  617. TemporaryChange restore_global_declarative_environment { m_global_declarative_environment, GCPtr { m_realm->global_environment().declarative_record() } };
  618. VERIFY(!vm().execution_context_stack().is_empty());
  619. auto& running_execution_context = vm().running_execution_context();
  620. if (running_execution_context.registers.size() < executable.number_of_registers)
  621. running_execution_context.registers.resize(executable.number_of_registers);
  622. TemporaryChange restore_registers { m_registers, running_execution_context.registers.span() };
  623. TemporaryChange restore_locals { m_locals, running_execution_context.locals.span() };
  624. reg(Register::accumulator()) = initial_accumulator_value;
  625. reg(Register::return_value()) = {};
  626. running_execution_context.executable = &executable;
  627. run_bytecode(entry_point.value_or(0));
  628. dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter did run unit {:p}", &executable);
  629. if constexpr (JS_BYTECODE_DEBUG) {
  630. for (size_t i = 0; i < registers().size(); ++i) {
  631. String value_string;
  632. if (registers()[i].is_empty())
  633. value_string = "(empty)"_string;
  634. else
  635. value_string = registers()[i].to_string_without_side_effects();
  636. dbgln("[{:3}] {}", i, value_string);
  637. }
  638. }
  639. auto return_value = js_undefined();
  640. if (!reg(Register::return_value()).is_empty())
  641. return_value = reg(Register::return_value());
  642. else if (!reg(Register::saved_return_value()).is_empty())
  643. return_value = reg(Register::saved_return_value());
  644. auto exception = reg(Register::exception());
  645. // At this point we may have already run any queued promise jobs via on_call_stack_emptied,
  646. // in which case this is a no-op.
  647. vm().run_queued_promise_jobs();
  648. vm().finish_execution_generation();
  649. if (!exception.is_empty())
  650. return { throw_completion(exception), vm().running_execution_context().registers[0] };
  651. return { return_value, vm().running_execution_context().registers[0] };
  652. }
  653. void Interpreter::enter_unwind_context()
  654. {
  655. auto& running_execution_context = vm().running_execution_context();
  656. running_execution_context.unwind_contexts.empend(
  657. m_current_executable,
  658. vm().running_execution_context().lexical_environment);
  659. running_execution_context.previously_scheduled_jumps.append(m_scheduled_jump);
  660. m_scheduled_jump = {};
  661. }
  662. void Interpreter::leave_unwind_context()
  663. {
  664. auto& running_execution_context = vm().running_execution_context();
  665. running_execution_context.unwind_contexts.take_last();
  666. }
  667. void Interpreter::catch_exception(Operand dst)
  668. {
  669. set(dst, reg(Register::exception()));
  670. reg(Register::exception()) = {};
  671. auto& running_execution_context = vm().running_execution_context();
  672. auto& context = running_execution_context.unwind_contexts.last();
  673. VERIFY(!context.handler_called);
  674. VERIFY(context.executable == &current_executable());
  675. context.handler_called = true;
  676. vm().running_execution_context().lexical_environment = context.lexical_environment;
  677. }
  678. void Interpreter::restore_scheduled_jump()
  679. {
  680. m_scheduled_jump = vm().running_execution_context().previously_scheduled_jumps.take_last();
  681. }
  682. void Interpreter::leave_finally()
  683. {
  684. reg(Register::exception()) = {};
  685. m_scheduled_jump = vm().running_execution_context().previously_scheduled_jumps.take_last();
  686. }
  687. void Interpreter::enter_object_environment(Object& object)
  688. {
  689. auto& running_execution_context = vm().running_execution_context();
  690. auto& old_environment = running_execution_context.lexical_environment;
  691. running_execution_context.saved_lexical_environments.append(old_environment);
  692. running_execution_context.lexical_environment = new_object_environment(object, true, old_environment);
  693. }
  694. ThrowCompletionOr<NonnullGCPtr<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, ReadonlySpan<FunctionParameter> parameters, FunctionKind kind, DeprecatedFlyString const& name)
  695. {
  696. auto executable_result = Bytecode::Generator::generate(vm, node, parameters, kind);
  697. if (executable_result.is_error())
  698. return vm.throw_completion<InternalError>(ErrorType::NotImplemented, TRY_OR_THROW_OOM(vm, executable_result.error().to_string()));
  699. auto bytecode_executable = executable_result.release_value();
  700. bytecode_executable->name = name;
  701. if (Bytecode::g_dump_bytecode)
  702. bytecode_executable->dump();
  703. return bytecode_executable;
  704. }
  705. }
  706. namespace JS::Bytecode {
  707. ByteString Instruction::to_byte_string(Bytecode::Executable const& executable) const
  708. {
  709. #define __BYTECODE_OP(op) \
  710. case Instruction::Type::op: \
  711. return static_cast<Bytecode::Op::op const&>(*this).to_byte_string_impl(executable);
  712. switch (type()) {
  713. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  714. default:
  715. VERIFY_NOT_REACHED();
  716. }
  717. #undef __BYTECODE_OP
  718. }
  719. }
  720. namespace JS::Bytecode::Op {
  721. static void dump_object(Object& o, HashTable<Object const*>& seen, int indent = 0)
  722. {
  723. if (seen.contains(&o))
  724. return;
  725. seen.set(&o);
  726. for (auto& it : o.shape().property_table()) {
  727. auto value = o.get_direct(it.value.offset);
  728. dbgln("{} {} -> {}", String::repeated(' ', indent).release_value(), it.key.to_display_string(), value);
  729. if (value.is_object()) {
  730. dump_object(value.as_object(), seen, indent + 2);
  731. }
  732. }
  733. }
  734. ThrowCompletionOr<void> Dump::execute_impl(Bytecode::Interpreter& interpreter) const
  735. {
  736. auto value = interpreter.get(m_value);
  737. dbgln("(DUMP) {}: {}", m_text, value);
  738. if (value.is_object()) {
  739. HashTable<Object const*> seen;
  740. dump_object(value.as_object(), seen);
  741. }
  742. return {};
  743. }
  744. ThrowCompletionOr<void> End::execute_impl(Bytecode::Interpreter&) const
  745. {
  746. // Handled in the interpreter loop.
  747. __builtin_unreachable();
  748. }
  749. #define JS_DEFINE_EXECUTE_FOR_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  750. ThrowCompletionOr<void> OpTitleCase::execute_impl(Bytecode::Interpreter& interpreter) const \
  751. { \
  752. auto& vm = interpreter.vm(); \
  753. auto lhs = interpreter.get(m_lhs); \
  754. auto rhs = interpreter.get(m_rhs); \
  755. interpreter.set(m_dst, TRY(op_snake_case(vm, lhs, rhs))); \
  756. return {}; \
  757. }
  758. #define JS_DEFINE_TO_BYTE_STRING_FOR_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
  759. ByteString OpTitleCase::to_byte_string_impl(Bytecode::Executable const& executable) const \
  760. { \
  761. return ByteString::formatted(#OpTitleCase " {}, {}, {}", \
  762. format_operand("dst"sv, m_dst, executable), \
  763. format_operand("lhs"sv, m_lhs, executable), \
  764. format_operand("rhs"sv, m_rhs, executable)); \
  765. }
  766. JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DEFINE_EXECUTE_FOR_COMMON_BINARY_OP)
  767. JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(JS_DEFINE_TO_BYTE_STRING_FOR_COMMON_BINARY_OP)
  768. JS_ENUMERATE_COMMON_BINARY_OPS_WITH_FAST_PATH(JS_DEFINE_TO_BYTE_STRING_FOR_COMMON_BINARY_OP)
  769. ThrowCompletionOr<void> Add::execute_impl(Bytecode::Interpreter& interpreter) const
  770. {
  771. auto& vm = interpreter.vm();
  772. auto const lhs = interpreter.get(m_lhs);
  773. auto const rhs = interpreter.get(m_rhs);
  774. if (lhs.is_number() && rhs.is_number()) {
  775. if (lhs.is_int32() && rhs.is_int32()) {
  776. if (!Checked<i32>::addition_would_overflow(lhs.as_i32(), rhs.as_i32())) {
  777. interpreter.set(m_dst, Value(lhs.as_i32() + rhs.as_i32()));
  778. return {};
  779. }
  780. }
  781. interpreter.set(m_dst, Value(lhs.as_double() + rhs.as_double()));
  782. return {};
  783. }
  784. interpreter.set(m_dst, TRY(add(vm, lhs, rhs)));
  785. return {};
  786. }
  787. ThrowCompletionOr<void> Mul::execute_impl(Bytecode::Interpreter& interpreter) const
  788. {
  789. auto& vm = interpreter.vm();
  790. auto const lhs = interpreter.get(m_lhs);
  791. auto const rhs = interpreter.get(m_rhs);
  792. if (lhs.is_number() && rhs.is_number()) {
  793. if (lhs.is_int32() && rhs.is_int32()) {
  794. if (!Checked<i32>::multiplication_would_overflow(lhs.as_i32(), rhs.as_i32())) {
  795. interpreter.set(m_dst, Value(lhs.as_i32() * rhs.as_i32()));
  796. return {};
  797. }
  798. }
  799. interpreter.set(m_dst, Value(lhs.as_double() * rhs.as_double()));
  800. return {};
  801. }
  802. interpreter.set(m_dst, TRY(mul(vm, lhs, rhs)));
  803. return {};
  804. }
  805. ThrowCompletionOr<void> Sub::execute_impl(Bytecode::Interpreter& interpreter) const
  806. {
  807. auto& vm = interpreter.vm();
  808. auto const lhs = interpreter.get(m_lhs);
  809. auto const rhs = interpreter.get(m_rhs);
  810. if (lhs.is_number() && rhs.is_number()) {
  811. if (lhs.is_int32() && rhs.is_int32()) {
  812. if (!Checked<i32>::addition_would_overflow(lhs.as_i32(), -rhs.as_i32())) {
  813. interpreter.set(m_dst, Value(lhs.as_i32() - rhs.as_i32()));
  814. return {};
  815. }
  816. }
  817. interpreter.set(m_dst, Value(lhs.as_double() - rhs.as_double()));
  818. return {};
  819. }
  820. interpreter.set(m_dst, TRY(sub(vm, lhs, rhs)));
  821. return {};
  822. }
  823. ThrowCompletionOr<void> BitwiseXor::execute_impl(Bytecode::Interpreter& interpreter) const
  824. {
  825. auto& vm = interpreter.vm();
  826. auto const lhs = interpreter.get(m_lhs);
  827. auto const rhs = interpreter.get(m_rhs);
  828. if (lhs.is_int32() && rhs.is_int32()) {
  829. interpreter.set(m_dst, Value(lhs.as_i32() ^ rhs.as_i32()));
  830. return {};
  831. }
  832. interpreter.set(m_dst, TRY(bitwise_xor(vm, lhs, rhs)));
  833. return {};
  834. }
  835. ThrowCompletionOr<void> BitwiseAnd::execute_impl(Bytecode::Interpreter& interpreter) const
  836. {
  837. auto& vm = interpreter.vm();
  838. auto const lhs = interpreter.get(m_lhs);
  839. auto const rhs = interpreter.get(m_rhs);
  840. if (lhs.is_int32() && rhs.is_int32()) {
  841. interpreter.set(m_dst, Value(lhs.as_i32() & rhs.as_i32()));
  842. return {};
  843. }
  844. interpreter.set(m_dst, TRY(bitwise_and(vm, lhs, rhs)));
  845. return {};
  846. }
  847. ThrowCompletionOr<void> BitwiseOr::execute_impl(Bytecode::Interpreter& interpreter) const
  848. {
  849. auto& vm = interpreter.vm();
  850. auto const lhs = interpreter.get(m_lhs);
  851. auto const rhs = interpreter.get(m_rhs);
  852. if (lhs.is_int32() && rhs.is_int32()) {
  853. interpreter.set(m_dst, Value(lhs.as_i32() | rhs.as_i32()));
  854. return {};
  855. }
  856. interpreter.set(m_dst, TRY(bitwise_or(vm, lhs, rhs)));
  857. return {};
  858. }
  859. ThrowCompletionOr<void> UnsignedRightShift::execute_impl(Bytecode::Interpreter& interpreter) const
  860. {
  861. auto& vm = interpreter.vm();
  862. auto const lhs = interpreter.get(m_lhs);
  863. auto const rhs = interpreter.get(m_rhs);
  864. if (lhs.is_int32() && rhs.is_int32()) {
  865. auto const shift_count = static_cast<u32>(rhs.as_i32()) % 32;
  866. interpreter.set(m_dst, Value(static_cast<u32>(lhs.as_i32()) >> shift_count));
  867. return {};
  868. }
  869. interpreter.set(m_dst, TRY(unsigned_right_shift(vm, lhs, rhs)));
  870. return {};
  871. }
  872. ThrowCompletionOr<void> RightShift::execute_impl(Bytecode::Interpreter& interpreter) const
  873. {
  874. auto& vm = interpreter.vm();
  875. auto const lhs = interpreter.get(m_lhs);
  876. auto const rhs = interpreter.get(m_rhs);
  877. if (lhs.is_int32() && rhs.is_int32()) {
  878. auto const shift_count = static_cast<u32>(rhs.as_i32()) % 32;
  879. interpreter.set(m_dst, Value(lhs.as_i32() >> shift_count));
  880. return {};
  881. }
  882. interpreter.set(m_dst, TRY(right_shift(vm, lhs, rhs)));
  883. return {};
  884. }
  885. ThrowCompletionOr<void> LeftShift::execute_impl(Bytecode::Interpreter& interpreter) const
  886. {
  887. auto& vm = interpreter.vm();
  888. auto const lhs = interpreter.get(m_lhs);
  889. auto const rhs = interpreter.get(m_rhs);
  890. if (lhs.is_int32() && rhs.is_int32()) {
  891. auto const shift_count = static_cast<u32>(rhs.as_i32()) % 32;
  892. interpreter.set(m_dst, Value(lhs.as_i32() << shift_count));
  893. return {};
  894. }
  895. interpreter.set(m_dst, TRY(left_shift(vm, lhs, rhs)));
  896. return {};
  897. }
  898. ThrowCompletionOr<void> LessThan::execute_impl(Bytecode::Interpreter& interpreter) const
  899. {
  900. auto& vm = interpreter.vm();
  901. auto const lhs = interpreter.get(m_lhs);
  902. auto const rhs = interpreter.get(m_rhs);
  903. if (lhs.is_int32() && rhs.is_int32()) {
  904. interpreter.set(m_dst, Value(lhs.as_i32() < rhs.as_i32()));
  905. return {};
  906. }
  907. interpreter.set(m_dst, TRY(less_than(vm, lhs, rhs)));
  908. return {};
  909. }
  910. ThrowCompletionOr<void> LessThanEquals::execute_impl(Bytecode::Interpreter& interpreter) const
  911. {
  912. auto& vm = interpreter.vm();
  913. auto const lhs = interpreter.get(m_lhs);
  914. auto const rhs = interpreter.get(m_rhs);
  915. if (lhs.is_int32() && rhs.is_int32()) {
  916. interpreter.set(m_dst, Value(lhs.as_i32() <= rhs.as_i32()));
  917. return {};
  918. }
  919. interpreter.set(m_dst, TRY(less_than_equals(vm, lhs, rhs)));
  920. return {};
  921. }
  922. ThrowCompletionOr<void> GreaterThan::execute_impl(Bytecode::Interpreter& interpreter) const
  923. {
  924. auto& vm = interpreter.vm();
  925. auto const lhs = interpreter.get(m_lhs);
  926. auto const rhs = interpreter.get(m_rhs);
  927. if (lhs.is_int32() && rhs.is_int32()) {
  928. interpreter.set(m_dst, Value(lhs.as_i32() > rhs.as_i32()));
  929. return {};
  930. }
  931. interpreter.set(m_dst, TRY(greater_than(vm, lhs, rhs)));
  932. return {};
  933. }
  934. ThrowCompletionOr<void> GreaterThanEquals::execute_impl(Bytecode::Interpreter& interpreter) const
  935. {
  936. auto& vm = interpreter.vm();
  937. auto const lhs = interpreter.get(m_lhs);
  938. auto const rhs = interpreter.get(m_rhs);
  939. if (lhs.is_int32() && rhs.is_int32()) {
  940. interpreter.set(m_dst, Value(lhs.as_i32() >= rhs.as_i32()));
  941. return {};
  942. }
  943. interpreter.set(m_dst, TRY(greater_than_equals(vm, lhs, rhs)));
  944. return {};
  945. }
  946. static ThrowCompletionOr<Value> not_(VM&, Value value)
  947. {
  948. return Value(!value.to_boolean());
  949. }
  950. static ThrowCompletionOr<Value> typeof_(VM& vm, Value value)
  951. {
  952. return PrimitiveString::create(vm, value.typeof());
  953. }
  954. #define JS_DEFINE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
  955. ThrowCompletionOr<void> OpTitleCase::execute_impl(Bytecode::Interpreter& interpreter) const \
  956. { \
  957. auto& vm = interpreter.vm(); \
  958. interpreter.set(dst(), TRY(op_snake_case(vm, interpreter.get(src())))); \
  959. return {}; \
  960. } \
  961. ByteString OpTitleCase::to_byte_string_impl(Bytecode::Executable const& executable) const \
  962. { \
  963. return ByteString::formatted(#OpTitleCase " {}, {}", \
  964. format_operand("dst"sv, dst(), executable), \
  965. format_operand("src"sv, src(), executable)); \
  966. }
  967. JS_ENUMERATE_COMMON_UNARY_OPS(JS_DEFINE_COMMON_UNARY_OP)
  968. ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interpreter) const
  969. {
  970. auto array = MUST(Array::create(interpreter.realm(), 0));
  971. for (size_t i = 0; i < m_element_count; i++) {
  972. array->indexed_properties().put(i, interpreter.get(m_elements[i]), default_attributes);
  973. }
  974. interpreter.set(dst(), array);
  975. return {};
  976. }
  977. ThrowCompletionOr<void> NewPrimitiveArray::execute_impl(Bytecode::Interpreter& interpreter) const
  978. {
  979. auto array = MUST(Array::create(interpreter.realm(), 0));
  980. for (size_t i = 0; i < m_element_count; i++)
  981. array->indexed_properties().put(i, m_elements[i], default_attributes);
  982. interpreter.set(dst(), array);
  983. return {};
  984. }
  985. ThrowCompletionOr<void> ArrayAppend::execute_impl(Bytecode::Interpreter& interpreter) const
  986. {
  987. return append(interpreter.vm(), interpreter.get(dst()), interpreter.get(src()), m_is_spread);
  988. }
  989. ThrowCompletionOr<void> ImportCall::execute_impl(Bytecode::Interpreter& interpreter) const
  990. {
  991. auto& vm = interpreter.vm();
  992. auto specifier = interpreter.get(m_specifier);
  993. auto options_value = interpreter.get(m_options);
  994. interpreter.set(dst(), TRY(perform_import_call(vm, specifier, options_value)));
  995. return {};
  996. }
  997. ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const
  998. {
  999. interpreter.set(dst(), TRY(iterator_to_array(interpreter.vm(), interpreter.get(iterator()))));
  1000. return {};
  1001. }
  1002. ThrowCompletionOr<void> NewObject::execute_impl(Bytecode::Interpreter& interpreter) const
  1003. {
  1004. auto& vm = interpreter.vm();
  1005. auto& realm = *vm.current_realm();
  1006. interpreter.set(dst(), Object::create(realm, realm.intrinsics().object_prototype()));
  1007. return {};
  1008. }
  1009. ThrowCompletionOr<void> NewRegExp::execute_impl(Bytecode::Interpreter& interpreter) const
  1010. {
  1011. interpreter.set(dst(),
  1012. new_regexp(
  1013. interpreter.vm(),
  1014. interpreter.current_executable().regex_table->get(m_regex_index),
  1015. interpreter.current_executable().get_string(m_source_index),
  1016. interpreter.current_executable().get_string(m_flags_index)));
  1017. return {};
  1018. }
  1019. #define JS_DEFINE_NEW_BUILTIN_ERROR_OP(ErrorName) \
  1020. ThrowCompletionOr<void> New##ErrorName::execute_impl(Bytecode::Interpreter& interpreter) const \
  1021. { \
  1022. auto& vm = interpreter.vm(); \
  1023. auto& realm = *vm.current_realm(); \
  1024. interpreter.set(dst(), ErrorName::create(realm, interpreter.current_executable().get_string(m_error_string))); \
  1025. return {}; \
  1026. } \
  1027. ByteString New##ErrorName::to_byte_string_impl(Bytecode::Executable const& executable) const \
  1028. { \
  1029. return ByteString::formatted("New" #ErrorName " {}, {}", \
  1030. format_operand("dst"sv, m_dst, executable), \
  1031. executable.string_table->get(m_error_string)); \
  1032. }
  1033. JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DEFINE_NEW_BUILTIN_ERROR_OP)
  1034. ThrowCompletionOr<void> CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const
  1035. {
  1036. auto& vm = interpreter.vm();
  1037. auto& realm = *vm.current_realm();
  1038. auto from_object = interpreter.get(m_from_object);
  1039. auto to_object = Object::create(realm, realm.intrinsics().object_prototype());
  1040. HashTable<PropertyKey> excluded_names;
  1041. for (size_t i = 0; i < m_excluded_names_count; ++i) {
  1042. excluded_names.set(TRY(interpreter.get(m_excluded_names[i]).to_property_key(vm)));
  1043. }
  1044. TRY(to_object->copy_data_properties(vm, from_object, excluded_names));
  1045. interpreter.set(dst(), to_object);
  1046. return {};
  1047. }
  1048. ThrowCompletionOr<void> ConcatString::execute_impl(Bytecode::Interpreter& interpreter) const
  1049. {
  1050. auto& vm = interpreter.vm();
  1051. auto string = TRY(interpreter.get(src()).to_primitive_string(vm));
  1052. interpreter.set(dst(), PrimitiveString::create(vm, interpreter.get(dst()).as_string(), string));
  1053. return {};
  1054. }
  1055. ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
  1056. {
  1057. interpreter.set(dst(), TRY(get_variable(interpreter, interpreter.current_executable().get_identifier(m_identifier), interpreter.current_executable().environment_variable_caches[m_cache_index])));
  1058. return {};
  1059. }
  1060. ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
  1061. {
  1062. auto callee_and_this = TRY(get_callee_and_this_from_environment(
  1063. interpreter,
  1064. interpreter.current_executable().get_identifier(m_identifier),
  1065. interpreter.current_executable().environment_variable_caches[m_cache_index]));
  1066. interpreter.set(m_callee, callee_and_this.callee);
  1067. interpreter.set(m_this_value, callee_and_this.this_value);
  1068. return {};
  1069. }
  1070. ThrowCompletionOr<void> GetGlobal::execute_impl(Bytecode::Interpreter& interpreter) const
  1071. {
  1072. interpreter.set(dst(), TRY(get_global(interpreter, interpreter.current_executable().get_identifier(m_identifier), interpreter.current_executable().global_variable_caches[m_cache_index])));
  1073. return {};
  1074. }
  1075. ThrowCompletionOr<void> DeleteVariable::execute_impl(Bytecode::Interpreter& interpreter) const
  1076. {
  1077. auto& vm = interpreter.vm();
  1078. auto const& string = interpreter.current_executable().get_identifier(m_identifier);
  1079. auto reference = TRY(vm.resolve_binding(string));
  1080. interpreter.set(dst(), Value(TRY(reference.delete_(vm))));
  1081. return {};
  1082. }
  1083. ThrowCompletionOr<void> CreateLexicalEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
  1084. {
  1085. auto make_and_swap_envs = [&](auto& old_environment) {
  1086. GCPtr<Environment> environment = new_declarative_environment(*old_environment).ptr();
  1087. swap(old_environment, environment);
  1088. return environment;
  1089. };
  1090. auto& running_execution_context = interpreter.vm().running_execution_context();
  1091. running_execution_context.saved_lexical_environments.append(make_and_swap_envs(running_execution_context.lexical_environment));
  1092. return {};
  1093. }
  1094. ThrowCompletionOr<void> EnterObjectEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
  1095. {
  1096. auto object = TRY(interpreter.get(m_object).to_object(interpreter.vm()));
  1097. interpreter.enter_object_environment(*object);
  1098. return {};
  1099. }
  1100. ThrowCompletionOr<void> Catch::execute_impl(Bytecode::Interpreter& interpreter) const
  1101. {
  1102. interpreter.catch_exception(dst());
  1103. return {};
  1104. }
  1105. ThrowCompletionOr<void> LeaveFinally::execute_impl(Bytecode::Interpreter& interpreter) const
  1106. {
  1107. interpreter.leave_finally();
  1108. return {};
  1109. }
  1110. ThrowCompletionOr<void> RestoreScheduledJump::execute_impl(Bytecode::Interpreter& interpreter) const
  1111. {
  1112. interpreter.restore_scheduled_jump();
  1113. return {};
  1114. }
  1115. ThrowCompletionOr<void> CreateVariable::execute_impl(Bytecode::Interpreter& interpreter) const
  1116. {
  1117. auto const& name = interpreter.current_executable().get_identifier(m_identifier);
  1118. return create_variable(interpreter.vm(), name, m_mode, m_is_global, m_is_immutable, m_is_strict);
  1119. }
  1120. ThrowCompletionOr<void> SetVariable::execute_impl(Bytecode::Interpreter& interpreter) const
  1121. {
  1122. auto& vm = interpreter.vm();
  1123. auto const& name = interpreter.current_executable().get_identifier(m_identifier);
  1124. TRY(set_variable(vm,
  1125. name,
  1126. interpreter.get(src()),
  1127. m_mode,
  1128. m_initialization_mode,
  1129. interpreter.current_executable().environment_variable_caches[m_cache_index]));
  1130. return {};
  1131. }
  1132. ThrowCompletionOr<void> SetLocal::execute_impl(Bytecode::Interpreter&) const
  1133. {
  1134. // Handled in the interpreter loop.
  1135. __builtin_unreachable();
  1136. }
  1137. ThrowCompletionOr<void> GetById::execute_impl(Bytecode::Interpreter& interpreter) const
  1138. {
  1139. auto base_identifier = interpreter.current_executable().get_identifier(m_base_identifier);
  1140. auto const& property_identifier = interpreter.current_executable().get_identifier(m_property);
  1141. auto base_value = interpreter.get(base());
  1142. auto& cache = interpreter.current_executable().property_lookup_caches[m_cache_index];
  1143. interpreter.set(dst(), TRY(get_by_id(interpreter.vm(), base_identifier, property_identifier, base_value, base_value, cache)));
  1144. return {};
  1145. }
  1146. ThrowCompletionOr<void> GetByIdWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1147. {
  1148. auto base_value = interpreter.get(m_base);
  1149. auto this_value = interpreter.get(m_this_value);
  1150. auto& cache = interpreter.current_executable().property_lookup_caches[m_cache_index];
  1151. interpreter.set(dst(), TRY(get_by_id(interpreter.vm(), {}, interpreter.current_executable().get_identifier(m_property), base_value, this_value, cache)));
  1152. return {};
  1153. }
  1154. ThrowCompletionOr<void> GetPrivateById::execute_impl(Bytecode::Interpreter& interpreter) const
  1155. {
  1156. auto& vm = interpreter.vm();
  1157. auto const& name = interpreter.current_executable().get_identifier(m_property);
  1158. auto base_value = interpreter.get(m_base);
  1159. auto private_reference = make_private_reference(vm, base_value, name);
  1160. interpreter.set(dst(), TRY(private_reference.get_value(vm)));
  1161. return {};
  1162. }
  1163. ThrowCompletionOr<void> HasPrivateId::execute_impl(Bytecode::Interpreter& interpreter) const
  1164. {
  1165. auto& vm = interpreter.vm();
  1166. auto base = interpreter.get(m_base);
  1167. if (!base.is_object())
  1168. return vm.throw_completion<TypeError>(ErrorType::InOperatorWithObject);
  1169. auto private_environment = vm.running_execution_context().private_environment;
  1170. VERIFY(private_environment);
  1171. auto private_name = private_environment->resolve_private_identifier(interpreter.current_executable().get_identifier(m_property));
  1172. interpreter.set(dst(), Value(base.as_object().private_element_find(private_name) != nullptr));
  1173. return {};
  1174. }
  1175. ThrowCompletionOr<void> PutById::execute_impl(Bytecode::Interpreter& interpreter) const
  1176. {
  1177. auto& vm = interpreter.vm();
  1178. auto value = interpreter.get(m_src);
  1179. auto base = interpreter.get(m_base);
  1180. auto base_identifier = interpreter.current_executable().get_identifier(m_base_identifier);
  1181. PropertyKey name = interpreter.current_executable().get_identifier(m_property);
  1182. auto& cache = interpreter.current_executable().property_lookup_caches[m_cache_index];
  1183. TRY(put_by_property_key(vm, base, base, value, base_identifier, name, m_kind, &cache));
  1184. return {};
  1185. }
  1186. ThrowCompletionOr<void> PutByIdWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1187. {
  1188. auto& vm = interpreter.vm();
  1189. auto value = interpreter.get(m_src);
  1190. auto base = interpreter.get(m_base);
  1191. PropertyKey name = interpreter.current_executable().get_identifier(m_property);
  1192. auto& cache = interpreter.current_executable().property_lookup_caches[m_cache_index];
  1193. TRY(put_by_property_key(vm, base, interpreter.get(m_this_value), value, {}, name, m_kind, &cache));
  1194. return {};
  1195. }
  1196. ThrowCompletionOr<void> PutPrivateById::execute_impl(Bytecode::Interpreter& interpreter) const
  1197. {
  1198. auto& vm = interpreter.vm();
  1199. auto value = interpreter.get(m_src);
  1200. auto object = TRY(interpreter.get(m_base).to_object(vm));
  1201. auto name = interpreter.current_executable().get_identifier(m_property);
  1202. auto private_reference = make_private_reference(vm, object, name);
  1203. TRY(private_reference.put_value(vm, value));
  1204. return {};
  1205. }
  1206. ThrowCompletionOr<void> DeleteById::execute_impl(Bytecode::Interpreter& interpreter) const
  1207. {
  1208. auto base_value = interpreter.get(m_base);
  1209. interpreter.set(dst(), TRY(Bytecode::delete_by_id(interpreter, base_value, m_property)));
  1210. return {};
  1211. }
  1212. ThrowCompletionOr<void> DeleteByIdWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1213. {
  1214. auto& vm = interpreter.vm();
  1215. auto base_value = interpreter.get(m_base);
  1216. auto const& identifier = interpreter.current_executable().get_identifier(m_property);
  1217. bool strict = vm.in_strict_mode();
  1218. auto reference = Reference { base_value, identifier, interpreter.get(m_this_value), strict };
  1219. interpreter.set(dst(), Value(TRY(reference.delete_(vm))));
  1220. return {};
  1221. }
  1222. ThrowCompletionOr<void> Jump::execute_impl(Bytecode::Interpreter&) const
  1223. {
  1224. // Handled in the interpreter loop.
  1225. __builtin_unreachable();
  1226. }
  1227. ThrowCompletionOr<void> ResolveThisBinding::execute_impl(Bytecode::Interpreter& interpreter) const
  1228. {
  1229. auto& cached_this_value = interpreter.reg(Register::this_value());
  1230. if (cached_this_value.is_empty()) {
  1231. // OPTIMIZATION: Because the value of 'this' cannot be reassigned during a function execution, it's
  1232. // resolved once and then saved for subsequent use.
  1233. auto& vm = interpreter.vm();
  1234. cached_this_value = TRY(vm.resolve_this_binding());
  1235. }
  1236. interpreter.set(dst(), cached_this_value);
  1237. return {};
  1238. }
  1239. // https://tc39.es/ecma262/#sec-makesuperpropertyreference
  1240. ThrowCompletionOr<void> ResolveSuperBase::execute_impl(Bytecode::Interpreter& interpreter) const
  1241. {
  1242. auto& vm = interpreter.vm();
  1243. // 1. Let env be GetThisEnvironment().
  1244. auto& env = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
  1245. // 2. Assert: env.HasSuperBinding() is true.
  1246. VERIFY(env.has_super_binding());
  1247. // 3. Let baseValue be ? env.GetSuperBase().
  1248. interpreter.set(dst(), TRY(env.get_super_base()));
  1249. return {};
  1250. }
  1251. ThrowCompletionOr<void> GetNewTarget::execute_impl(Bytecode::Interpreter& interpreter) const
  1252. {
  1253. interpreter.set(dst(), interpreter.vm().get_new_target());
  1254. return {};
  1255. }
  1256. ThrowCompletionOr<void> GetImportMeta::execute_impl(Bytecode::Interpreter& interpreter) const
  1257. {
  1258. interpreter.set(dst(), interpreter.vm().get_import_meta());
  1259. return {};
  1260. }
  1261. ThrowCompletionOr<void> JumpIf::execute_impl(Bytecode::Interpreter&) const
  1262. {
  1263. // Handled in the interpreter loop.
  1264. __builtin_unreachable();
  1265. }
  1266. ThrowCompletionOr<void> JumpTrue::execute_impl(Bytecode::Interpreter&) const
  1267. {
  1268. // Handled in the interpreter loop.
  1269. __builtin_unreachable();
  1270. }
  1271. ThrowCompletionOr<void> JumpFalse::execute_impl(Bytecode::Interpreter&) const
  1272. {
  1273. // Handled in the interpreter loop.
  1274. __builtin_unreachable();
  1275. }
  1276. ThrowCompletionOr<void> JumpUndefined::execute_impl(Bytecode::Interpreter&) const
  1277. {
  1278. // Handled in the interpreter loop.
  1279. __builtin_unreachable();
  1280. }
  1281. ThrowCompletionOr<void> JumpNullish::execute_impl(Bytecode::Interpreter&) const
  1282. {
  1283. // Handled in the interpreter loop.
  1284. __builtin_unreachable();
  1285. }
  1286. ThrowCompletionOr<void> Mov::execute_impl(Bytecode::Interpreter&) const
  1287. {
  1288. // Handled in the interpreter loop.
  1289. __builtin_unreachable();
  1290. }
  1291. static ThrowCompletionOr<Value> dispatch_builtin_call(Bytecode::Interpreter& interpreter, Bytecode::Builtin builtin, ReadonlySpan<Operand> arguments)
  1292. {
  1293. switch (builtin) {
  1294. case Builtin::MathAbs:
  1295. return TRY(MathObject::abs_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1296. case Builtin::MathLog:
  1297. return TRY(MathObject::log_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1298. case Builtin::MathPow:
  1299. return TRY(MathObject::pow_impl(interpreter.vm(), interpreter.get(arguments[0]), interpreter.get(arguments[1])));
  1300. case Builtin::MathExp:
  1301. return TRY(MathObject::exp_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1302. case Builtin::MathCeil:
  1303. return TRY(MathObject::ceil_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1304. case Builtin::MathFloor:
  1305. return TRY(MathObject::floor_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1306. case Builtin::MathRound:
  1307. return TRY(MathObject::round_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1308. case Builtin::MathSqrt:
  1309. return TRY(MathObject::sqrt_impl(interpreter.vm(), interpreter.get(arguments[0])));
  1310. case Bytecode::Builtin::__Count:
  1311. VERIFY_NOT_REACHED();
  1312. }
  1313. VERIFY_NOT_REACHED();
  1314. }
  1315. ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const
  1316. {
  1317. auto callee = interpreter.get(m_callee);
  1318. TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string()));
  1319. if (m_builtin.has_value()
  1320. && m_argument_count == Bytecode::builtin_argument_count(m_builtin.value())
  1321. && callee.is_object()
  1322. && interpreter.realm().get_builtin_value(m_builtin.value()) == &callee.as_object()) {
  1323. interpreter.set(dst(), TRY(dispatch_builtin_call(interpreter, m_builtin.value(), { m_arguments, m_argument_count })));
  1324. return {};
  1325. }
  1326. Vector<Value> argument_values;
  1327. argument_values.ensure_capacity(m_argument_count);
  1328. for (size_t i = 0; i < m_argument_count; ++i)
  1329. argument_values.unchecked_append(interpreter.get(m_arguments[i]));
  1330. interpreter.set(dst(), TRY(perform_call(interpreter, interpreter.get(m_this_value), call_type(), callee, argument_values)));
  1331. return {};
  1332. }
  1333. ThrowCompletionOr<void> CallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const
  1334. {
  1335. auto callee = interpreter.get(m_callee);
  1336. TRY(throw_if_needed_for_call(interpreter, callee, call_type(), expression_string()));
  1337. auto argument_values = argument_list_evaluation(interpreter.vm(), interpreter.get(arguments()));
  1338. interpreter.set(dst(), TRY(perform_call(interpreter, interpreter.get(m_this_value), call_type(), callee, move(argument_values))));
  1339. return {};
  1340. }
  1341. // 13.3.7.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
  1342. ThrowCompletionOr<void> SuperCallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const
  1343. {
  1344. interpreter.set(dst(), TRY(super_call_with_argument_array(interpreter.vm(), interpreter.get(arguments()), m_is_synthetic)));
  1345. return {};
  1346. }
  1347. ThrowCompletionOr<void> NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const
  1348. {
  1349. auto& vm = interpreter.vm();
  1350. interpreter.set(dst(), new_function(vm, m_function_node, m_lhs_name, m_home_object));
  1351. return {};
  1352. }
  1353. ThrowCompletionOr<void> Return::execute_impl(Bytecode::Interpreter& interpreter) const
  1354. {
  1355. if (m_value.has_value())
  1356. interpreter.do_return(interpreter.get(*m_value));
  1357. else
  1358. interpreter.do_return(js_undefined());
  1359. return {};
  1360. }
  1361. ThrowCompletionOr<void> Increment::execute_impl(Bytecode::Interpreter& interpreter) const
  1362. {
  1363. auto& vm = interpreter.vm();
  1364. auto old_value = interpreter.get(dst());
  1365. // OPTIMIZATION: Fast path for Int32 values.
  1366. if (old_value.is_int32()) {
  1367. auto integer_value = old_value.as_i32();
  1368. if (integer_value != NumericLimits<i32>::max()) [[likely]] {
  1369. interpreter.set(dst(), Value { integer_value + 1 });
  1370. return {};
  1371. }
  1372. }
  1373. old_value = TRY(old_value.to_numeric(vm));
  1374. if (old_value.is_number())
  1375. interpreter.set(dst(), Value(old_value.as_double() + 1));
  1376. else
  1377. interpreter.set(dst(), BigInt::create(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 })));
  1378. return {};
  1379. }
  1380. ThrowCompletionOr<void> PostfixIncrement::execute_impl(Bytecode::Interpreter& interpreter) const
  1381. {
  1382. auto& vm = interpreter.vm();
  1383. auto old_value = interpreter.get(m_src);
  1384. // OPTIMIZATION: Fast path for Int32 values.
  1385. if (old_value.is_int32()) {
  1386. auto integer_value = old_value.as_i32();
  1387. if (integer_value != NumericLimits<i32>::max()) [[likely]] {
  1388. interpreter.set(m_dst, old_value);
  1389. interpreter.set(m_src, Value { integer_value + 1 });
  1390. return {};
  1391. }
  1392. }
  1393. old_value = TRY(old_value.to_numeric(vm));
  1394. interpreter.set(m_dst, old_value);
  1395. if (old_value.is_number())
  1396. interpreter.set(m_src, Value(old_value.as_double() + 1));
  1397. else
  1398. interpreter.set(m_src, BigInt::create(vm, old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 })));
  1399. return {};
  1400. }
  1401. ThrowCompletionOr<void> Decrement::execute_impl(Bytecode::Interpreter& interpreter) const
  1402. {
  1403. auto& vm = interpreter.vm();
  1404. auto old_value = interpreter.get(dst());
  1405. old_value = TRY(old_value.to_numeric(vm));
  1406. if (old_value.is_number())
  1407. interpreter.set(dst(), Value(old_value.as_double() - 1));
  1408. else
  1409. interpreter.set(dst(), BigInt::create(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 })));
  1410. return {};
  1411. }
  1412. ThrowCompletionOr<void> PostfixDecrement::execute_impl(Bytecode::Interpreter& interpreter) const
  1413. {
  1414. auto& vm = interpreter.vm();
  1415. auto old_value = interpreter.get(m_src);
  1416. old_value = TRY(old_value.to_numeric(vm));
  1417. interpreter.set(m_dst, old_value);
  1418. if (old_value.is_number())
  1419. interpreter.set(m_src, Value(old_value.as_double() - 1));
  1420. else
  1421. interpreter.set(m_src, BigInt::create(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 })));
  1422. return {};
  1423. }
  1424. ThrowCompletionOr<void> Throw::execute_impl(Bytecode::Interpreter& interpreter) const
  1425. {
  1426. return throw_completion(interpreter.get(src()));
  1427. }
  1428. ThrowCompletionOr<void> ThrowIfNotObject::execute_impl(Bytecode::Interpreter& interpreter) const
  1429. {
  1430. auto& vm = interpreter.vm();
  1431. auto src = interpreter.get(m_src);
  1432. if (!src.is_object())
  1433. return vm.throw_completion<TypeError>(ErrorType::NotAnObject, src.to_string_without_side_effects());
  1434. return {};
  1435. }
  1436. ThrowCompletionOr<void> ThrowIfNullish::execute_impl(Bytecode::Interpreter& interpreter) const
  1437. {
  1438. auto& vm = interpreter.vm();
  1439. auto value = interpreter.get(m_src);
  1440. if (value.is_nullish())
  1441. return vm.throw_completion<TypeError>(ErrorType::NotObjectCoercible, value.to_string_without_side_effects());
  1442. return {};
  1443. }
  1444. ThrowCompletionOr<void> ThrowIfTDZ::execute_impl(Bytecode::Interpreter& interpreter) const
  1445. {
  1446. auto& vm = interpreter.vm();
  1447. auto value = interpreter.get(m_src);
  1448. if (value.is_empty())
  1449. return vm.throw_completion<ReferenceError>(ErrorType::BindingNotInitialized, value.to_string_without_side_effects());
  1450. return {};
  1451. }
  1452. ThrowCompletionOr<void> EnterUnwindContext::execute_impl(Bytecode::Interpreter&) const
  1453. {
  1454. // Handled in the interpreter loop.
  1455. __builtin_unreachable();
  1456. }
  1457. ThrowCompletionOr<void> ScheduleJump::execute_impl(Bytecode::Interpreter&) const
  1458. {
  1459. // Handled in the interpreter loop.
  1460. __builtin_unreachable();
  1461. }
  1462. ThrowCompletionOr<void> LeaveLexicalEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
  1463. {
  1464. auto& running_execution_context = interpreter.vm().running_execution_context();
  1465. running_execution_context.lexical_environment = running_execution_context.saved_lexical_environments.take_last();
  1466. return {};
  1467. }
  1468. ThrowCompletionOr<void> LeaveUnwindContext::execute_impl(Bytecode::Interpreter& interpreter) const
  1469. {
  1470. interpreter.leave_unwind_context();
  1471. return {};
  1472. }
  1473. ThrowCompletionOr<void> ContinuePendingUnwind::execute_impl(Bytecode::Interpreter&) const
  1474. {
  1475. // Handled in the interpreter loop.
  1476. __builtin_unreachable();
  1477. }
  1478. ThrowCompletionOr<void> Yield::execute_impl(Bytecode::Interpreter& interpreter) const
  1479. {
  1480. auto yielded_value = interpreter.get(m_value).value_or(js_undefined());
  1481. auto object = Object::create(interpreter.realm(), nullptr);
  1482. object->define_direct_property("result", yielded_value, JS::default_attributes);
  1483. if (m_continuation_label.has_value())
  1484. // FIXME: If we get a pointer, which is not accurately representable as a double
  1485. // will cause this to explode
  1486. object->define_direct_property("continuation", Value(m_continuation_label->address()), JS::default_attributes);
  1487. else
  1488. object->define_direct_property("continuation", js_null(), JS::default_attributes);
  1489. object->define_direct_property("isAwait", Value(false), JS::default_attributes);
  1490. interpreter.do_return(object);
  1491. return {};
  1492. }
  1493. ThrowCompletionOr<void> Await::execute_impl(Bytecode::Interpreter& interpreter) const
  1494. {
  1495. auto yielded_value = interpreter.get(m_argument).value_or(js_undefined());
  1496. auto object = Object::create(interpreter.realm(), nullptr);
  1497. object->define_direct_property("result", yielded_value, JS::default_attributes);
  1498. // FIXME: If we get a pointer, which is not accurately representable as a double
  1499. // will cause this to explode
  1500. object->define_direct_property("continuation", Value(m_continuation_label.address()), JS::default_attributes);
  1501. object->define_direct_property("isAwait", Value(true), JS::default_attributes);
  1502. interpreter.do_return(object);
  1503. return {};
  1504. }
  1505. ThrowCompletionOr<void> GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const
  1506. {
  1507. auto base_identifier = interpreter.current_executable().get_identifier(m_base_identifier);
  1508. interpreter.set(dst(), TRY(get_by_value(interpreter.vm(), base_identifier, interpreter.get(m_base), interpreter.get(m_property))));
  1509. return {};
  1510. }
  1511. ThrowCompletionOr<void> GetByValueWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1512. {
  1513. auto& vm = interpreter.vm();
  1514. auto property_key_value = interpreter.get(m_property);
  1515. auto object = TRY(interpreter.get(m_base).to_object(vm));
  1516. auto property_key = TRY(property_key_value.to_property_key(vm));
  1517. interpreter.set(dst(), TRY(object->internal_get(property_key, interpreter.get(m_this_value))));
  1518. return {};
  1519. }
  1520. ThrowCompletionOr<void> PutByValue::execute_impl(Bytecode::Interpreter& interpreter) const
  1521. {
  1522. auto& vm = interpreter.vm();
  1523. auto value = interpreter.get(m_src);
  1524. auto base_identifier = interpreter.current_executable().get_identifier(m_base_identifier);
  1525. TRY(put_by_value(vm, interpreter.get(m_base), base_identifier, interpreter.get(m_property), value, m_kind));
  1526. return {};
  1527. }
  1528. ThrowCompletionOr<void> PutByValueWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1529. {
  1530. auto& vm = interpreter.vm();
  1531. auto value = interpreter.get(m_src);
  1532. auto base = interpreter.get(m_base);
  1533. auto property_key = m_kind != PropertyKind::Spread ? TRY(interpreter.get(m_property).to_property_key(vm)) : PropertyKey {};
  1534. TRY(put_by_property_key(vm, base, interpreter.get(m_this_value), value, {}, property_key, m_kind));
  1535. return {};
  1536. }
  1537. ThrowCompletionOr<void> DeleteByValue::execute_impl(Bytecode::Interpreter& interpreter) const
  1538. {
  1539. auto base_value = interpreter.get(m_base);
  1540. auto property_key_value = interpreter.get(m_property);
  1541. interpreter.set(dst(), TRY(delete_by_value(interpreter, base_value, property_key_value)));
  1542. return {};
  1543. }
  1544. ThrowCompletionOr<void> DeleteByValueWithThis::execute_impl(Bytecode::Interpreter& interpreter) const
  1545. {
  1546. auto property_key_value = interpreter.get(m_property);
  1547. auto base_value = interpreter.get(m_base);
  1548. auto this_value = interpreter.get(m_this_value);
  1549. interpreter.set(dst(), TRY(delete_by_value_with_this(interpreter, base_value, property_key_value, this_value)));
  1550. return {};
  1551. }
  1552. ThrowCompletionOr<void> GetIterator::execute_impl(Bytecode::Interpreter& interpreter) const
  1553. {
  1554. auto& vm = interpreter.vm();
  1555. interpreter.set(dst(), TRY(get_iterator(vm, interpreter.get(iterable()), m_hint)));
  1556. return {};
  1557. }
  1558. ThrowCompletionOr<void> GetObjectFromIteratorRecord::execute_impl(Bytecode::Interpreter& interpreter) const
  1559. {
  1560. auto& iterator_record = verify_cast<IteratorRecord>(interpreter.get(m_iterator_record).as_object());
  1561. interpreter.set(m_object, iterator_record.iterator);
  1562. return {};
  1563. }
  1564. ThrowCompletionOr<void> GetNextMethodFromIteratorRecord::execute_impl(Bytecode::Interpreter& interpreter) const
  1565. {
  1566. auto& iterator_record = verify_cast<IteratorRecord>(interpreter.get(m_iterator_record).as_object());
  1567. interpreter.set(m_next_method, iterator_record.next_method);
  1568. return {};
  1569. }
  1570. ThrowCompletionOr<void> GetMethod::execute_impl(Bytecode::Interpreter& interpreter) const
  1571. {
  1572. auto& vm = interpreter.vm();
  1573. auto identifier = interpreter.current_executable().get_identifier(m_property);
  1574. auto method = TRY(interpreter.get(m_object).get_method(vm, identifier));
  1575. interpreter.set(dst(), method ?: js_undefined());
  1576. return {};
  1577. }
  1578. ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interpreter& interpreter) const
  1579. {
  1580. interpreter.set(dst(), TRY(get_object_property_iterator(interpreter.vm(), interpreter.get(object()))));
  1581. return {};
  1582. }
  1583. ThrowCompletionOr<void> IteratorClose::execute_impl(Bytecode::Interpreter& interpreter) const
  1584. {
  1585. auto& vm = interpreter.vm();
  1586. auto& iterator = verify_cast<IteratorRecord>(interpreter.get(m_iterator_record).as_object());
  1587. // FIXME: Return the value of the resulting completion. (Note that m_completion_value can be empty!)
  1588. TRY(iterator_close(vm, iterator, Completion { m_completion_type, m_completion_value, {} }));
  1589. return {};
  1590. }
  1591. ThrowCompletionOr<void> AsyncIteratorClose::execute_impl(Bytecode::Interpreter& interpreter) const
  1592. {
  1593. auto& vm = interpreter.vm();
  1594. auto& iterator = verify_cast<IteratorRecord>(interpreter.get(m_iterator_record).as_object());
  1595. // FIXME: Return the value of the resulting completion. (Note that m_completion_value can be empty!)
  1596. TRY(async_iterator_close(vm, iterator, Completion { m_completion_type, m_completion_value, {} }));
  1597. return {};
  1598. }
  1599. ThrowCompletionOr<void> IteratorNext::execute_impl(Bytecode::Interpreter& interpreter) const
  1600. {
  1601. auto& vm = interpreter.vm();
  1602. auto& iterator_record = verify_cast<IteratorRecord>(interpreter.get(m_iterator_record).as_object());
  1603. interpreter.set(dst(), TRY(iterator_next(vm, iterator_record)));
  1604. return {};
  1605. }
  1606. ThrowCompletionOr<void> NewClass::execute_impl(Bytecode::Interpreter& interpreter) const
  1607. {
  1608. Value super_class;
  1609. if (m_super_class.has_value())
  1610. super_class = interpreter.get(m_super_class.value());
  1611. interpreter.set(dst(), TRY(new_class(interpreter.vm(), super_class, m_class_expression, m_lhs_name)));
  1612. return {};
  1613. }
  1614. // 13.5.3.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-typeof-operator-runtime-semantics-evaluation
  1615. ThrowCompletionOr<void> TypeofVariable::execute_impl(Bytecode::Interpreter& interpreter) const
  1616. {
  1617. auto& vm = interpreter.vm();
  1618. interpreter.set(dst(), TRY(typeof_variable(vm, interpreter.current_executable().get_identifier(m_identifier))));
  1619. return {};
  1620. }
  1621. ThrowCompletionOr<void> BlockDeclarationInstantiation::execute_impl(Bytecode::Interpreter& interpreter) const
  1622. {
  1623. auto& vm = interpreter.vm();
  1624. auto old_environment = vm.running_execution_context().lexical_environment;
  1625. auto& running_execution_context = vm.running_execution_context();
  1626. running_execution_context.saved_lexical_environments.append(old_environment);
  1627. running_execution_context.lexical_environment = new_declarative_environment(*old_environment);
  1628. m_scope_node.block_declaration_instantiation(vm, running_execution_context.lexical_environment);
  1629. return {};
  1630. }
  1631. ByteString Mov::to_byte_string_impl(Bytecode::Executable const& executable) const
  1632. {
  1633. return ByteString::formatted("Mov {}, {}",
  1634. format_operand("dst"sv, m_dst, executable),
  1635. format_operand("src"sv, m_src, executable));
  1636. }
  1637. ByteString NewArray::to_byte_string_impl(Bytecode::Executable const& executable) const
  1638. {
  1639. StringBuilder builder;
  1640. builder.appendff("NewArray {}", format_operand("dst"sv, dst(), executable));
  1641. if (m_element_count != 0) {
  1642. builder.appendff(", {}", format_operand_list("args"sv, { m_elements, m_element_count }, executable));
  1643. }
  1644. return builder.to_byte_string();
  1645. }
  1646. ByteString NewPrimitiveArray::to_byte_string_impl(Bytecode::Executable const& executable) const
  1647. {
  1648. return ByteString::formatted("NewPrimitiveArray {}, {}"sv,
  1649. format_operand("dst"sv, dst(), executable),
  1650. format_value_list("elements"sv, elements()));
  1651. }
  1652. ByteString ArrayAppend::to_byte_string_impl(Bytecode::Executable const& executable) const
  1653. {
  1654. return ByteString::formatted("Append {}, {}{}",
  1655. format_operand("dst"sv, dst(), executable),
  1656. format_operand("src"sv, src(), executable),
  1657. m_is_spread ? " **"sv : ""sv);
  1658. }
  1659. ByteString IteratorToArray::to_byte_string_impl(Bytecode::Executable const& executable) const
  1660. {
  1661. return ByteString::formatted("IteratorToArray {}, {}",
  1662. format_operand("dst"sv, dst(), executable),
  1663. format_operand("iterator"sv, iterator(), executable));
  1664. }
  1665. ByteString NewObject::to_byte_string_impl(Bytecode::Executable const& executable) const
  1666. {
  1667. return ByteString::formatted("NewObject {}", format_operand("dst"sv, dst(), executable));
  1668. }
  1669. ByteString NewRegExp::to_byte_string_impl(Bytecode::Executable const& executable) const
  1670. {
  1671. return ByteString::formatted("NewRegExp {}, source:{} (\"{}\") flags:{} (\"{}\")",
  1672. format_operand("dst"sv, dst(), executable),
  1673. m_source_index, executable.get_string(m_source_index), m_flags_index, executable.get_string(m_flags_index));
  1674. }
  1675. ByteString CopyObjectExcludingProperties::to_byte_string_impl(Bytecode::Executable const& executable) const
  1676. {
  1677. StringBuilder builder;
  1678. builder.appendff("CopyObjectExcludingProperties {}, {}",
  1679. format_operand("dst"sv, dst(), executable),
  1680. format_operand("from"sv, m_from_object, executable));
  1681. if (m_excluded_names_count != 0) {
  1682. builder.append(" excluding:["sv);
  1683. for (size_t i = 0; i < m_excluded_names_count; ++i) {
  1684. if (i != 0)
  1685. builder.append(", "sv);
  1686. builder.append(format_operand("#"sv, m_excluded_names[i], executable));
  1687. }
  1688. builder.append(']');
  1689. }
  1690. return builder.to_byte_string();
  1691. }
  1692. ByteString ConcatString::to_byte_string_impl(Bytecode::Executable const& executable) const
  1693. {
  1694. return ByteString::formatted("ConcatString {}, {}",
  1695. format_operand("dst"sv, dst(), executable),
  1696. format_operand("src"sv, src(), executable));
  1697. }
  1698. ByteString GetCalleeAndThisFromEnvironment::to_byte_string_impl(Bytecode::Executable const& executable) const
  1699. {
  1700. return ByteString::formatted("GetCalleeAndThisFromEnvironment {}, {} <- {}",
  1701. format_operand("callee"sv, m_callee, executable),
  1702. format_operand("this"sv, m_this_value, executable),
  1703. executable.identifier_table->get(m_identifier));
  1704. }
  1705. ByteString GetVariable::to_byte_string_impl(Bytecode::Executable const& executable) const
  1706. {
  1707. return ByteString::formatted("GetVariable {}, {}",
  1708. format_operand("dst"sv, dst(), executable),
  1709. executable.identifier_table->get(m_identifier));
  1710. }
  1711. ByteString GetGlobal::to_byte_string_impl(Bytecode::Executable const& executable) const
  1712. {
  1713. return ByteString::formatted("GetGlobal {}, {}", format_operand("dst"sv, dst(), executable),
  1714. executable.identifier_table->get(m_identifier));
  1715. }
  1716. ByteString DeleteVariable::to_byte_string_impl(Bytecode::Executable const& executable) const
  1717. {
  1718. return ByteString::formatted("DeleteVariable {}", executable.identifier_table->get(m_identifier));
  1719. }
  1720. ByteString CreateLexicalEnvironment::to_byte_string_impl(Bytecode::Executable const&) const
  1721. {
  1722. return "CreateLexicalEnvironment"sv;
  1723. }
  1724. ByteString CreateVariable::to_byte_string_impl(Bytecode::Executable const& executable) const
  1725. {
  1726. auto mode_string = m_mode == EnvironmentMode::Lexical ? "Lexical" : "Variable";
  1727. return ByteString::formatted("CreateVariable env:{} immutable:{} global:{} {}", mode_string, m_is_immutable, m_is_global, executable.identifier_table->get(m_identifier));
  1728. }
  1729. ByteString EnterObjectEnvironment::to_byte_string_impl(Executable const& executable) const
  1730. {
  1731. return ByteString::formatted("EnterObjectEnvironment {}",
  1732. format_operand("object"sv, m_object, executable));
  1733. }
  1734. ByteString SetVariable::to_byte_string_impl(Bytecode::Executable const& executable) const
  1735. {
  1736. auto initialization_mode_name = m_initialization_mode == InitializationMode::Initialize ? "Initialize" : "Set";
  1737. auto mode_string = m_mode == EnvironmentMode::Lexical ? "Lexical" : "Variable";
  1738. return ByteString::formatted("SetVariable {}, {}, env:{} init:{}",
  1739. executable.identifier_table->get(m_identifier),
  1740. format_operand("src"sv, src(), executable),
  1741. mode_string, initialization_mode_name);
  1742. }
  1743. ByteString SetLocal::to_byte_string_impl(Bytecode::Executable const& executable) const
  1744. {
  1745. return ByteString::formatted("SetLocal {}, {}",
  1746. format_operand("dst"sv, dst(), executable),
  1747. format_operand("src"sv, src(), executable));
  1748. }
  1749. static StringView property_kind_to_string(PropertyKind kind)
  1750. {
  1751. switch (kind) {
  1752. case PropertyKind::Getter:
  1753. return "getter"sv;
  1754. case PropertyKind::Setter:
  1755. return "setter"sv;
  1756. case PropertyKind::KeyValue:
  1757. return "key-value"sv;
  1758. case PropertyKind::DirectKeyValue:
  1759. return "direct-key-value"sv;
  1760. case PropertyKind::Spread:
  1761. return "spread"sv;
  1762. case PropertyKind::ProtoSetter:
  1763. return "proto-setter"sv;
  1764. }
  1765. VERIFY_NOT_REACHED();
  1766. }
  1767. ByteString PutById::to_byte_string_impl(Bytecode::Executable const& executable) const
  1768. {
  1769. auto kind = property_kind_to_string(m_kind);
  1770. return ByteString::formatted("PutById {}, {}, {}, kind:{}",
  1771. format_operand("base"sv, m_base, executable),
  1772. executable.identifier_table->get(m_property),
  1773. format_operand("src"sv, m_src, executable),
  1774. kind);
  1775. }
  1776. ByteString PutByIdWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  1777. {
  1778. auto kind = property_kind_to_string(m_kind);
  1779. return ByteString::formatted("PutByIdWithThis {}, {}, {}, {}, kind:{}",
  1780. format_operand("base"sv, m_base, executable),
  1781. executable.identifier_table->get(m_property),
  1782. format_operand("src"sv, m_src, executable),
  1783. format_operand("this"sv, m_this_value, executable),
  1784. kind);
  1785. }
  1786. ByteString PutPrivateById::to_byte_string_impl(Bytecode::Executable const& executable) const
  1787. {
  1788. auto kind = property_kind_to_string(m_kind);
  1789. return ByteString::formatted(
  1790. "PutPrivateById {}, {}, {}, kind:{} ",
  1791. format_operand("base"sv, m_base, executable),
  1792. executable.identifier_table->get(m_property),
  1793. format_operand("src"sv, m_src, executable),
  1794. kind);
  1795. }
  1796. ByteString GetById::to_byte_string_impl(Bytecode::Executable const& executable) const
  1797. {
  1798. return ByteString::formatted("GetById {}, {}, {}",
  1799. format_operand("dst"sv, m_dst, executable),
  1800. format_operand("base"sv, m_base, executable),
  1801. executable.identifier_table->get(m_property));
  1802. }
  1803. ByteString GetByIdWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  1804. {
  1805. return ByteString::formatted("GetByIdWithThis {}, {}, {}, {}",
  1806. format_operand("dst"sv, m_dst, executable),
  1807. format_operand("base"sv, m_base, executable),
  1808. executable.identifier_table->get(m_property),
  1809. format_operand("this"sv, m_this_value, executable));
  1810. }
  1811. ByteString GetPrivateById::to_byte_string_impl(Bytecode::Executable const& executable) const
  1812. {
  1813. return ByteString::formatted("GetPrivateById {}, {}, {}",
  1814. format_operand("dst"sv, m_dst, executable),
  1815. format_operand("base"sv, m_base, executable),
  1816. executable.identifier_table->get(m_property));
  1817. }
  1818. ByteString HasPrivateId::to_byte_string_impl(Bytecode::Executable const& executable) const
  1819. {
  1820. return ByteString::formatted("HasPrivateId {}, {}, {}",
  1821. format_operand("dst"sv, m_dst, executable),
  1822. format_operand("base"sv, m_base, executable),
  1823. executable.identifier_table->get(m_property));
  1824. }
  1825. ByteString DeleteById::to_byte_string_impl(Bytecode::Executable const& executable) const
  1826. {
  1827. return ByteString::formatted("DeleteById {}, {}, {}",
  1828. format_operand("dst"sv, m_dst, executable),
  1829. format_operand("base"sv, m_base, executable),
  1830. executable.identifier_table->get(m_property));
  1831. }
  1832. ByteString DeleteByIdWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  1833. {
  1834. return ByteString::formatted("DeleteByIdWithThis {}, {}, {}, {}",
  1835. format_operand("dst"sv, m_dst, executable),
  1836. format_operand("base"sv, m_base, executable),
  1837. executable.identifier_table->get(m_property),
  1838. format_operand("this"sv, m_this_value, executable));
  1839. }
  1840. ByteString Jump::to_byte_string_impl(Bytecode::Executable const&) const
  1841. {
  1842. return ByteString::formatted("Jump {}", m_target);
  1843. }
  1844. ByteString JumpIf::to_byte_string_impl(Bytecode::Executable const& executable) const
  1845. {
  1846. return ByteString::formatted("JumpIf {}, \033[32mtrue\033[0m:{} \033[32mfalse\033[0m:{}",
  1847. format_operand("condition"sv, m_condition, executable),
  1848. m_true_target,
  1849. m_false_target);
  1850. }
  1851. ByteString JumpTrue::to_byte_string_impl(Bytecode::Executable const& executable) const
  1852. {
  1853. return ByteString::formatted("JumpTrue {}, {}",
  1854. format_operand("condition"sv, m_condition, executable),
  1855. m_target);
  1856. }
  1857. ByteString JumpFalse::to_byte_string_impl(Bytecode::Executable const& executable) const
  1858. {
  1859. return ByteString::formatted("JumpFalse {}, {}",
  1860. format_operand("condition"sv, m_condition, executable),
  1861. m_target);
  1862. }
  1863. ByteString JumpNullish::to_byte_string_impl(Bytecode::Executable const& executable) const
  1864. {
  1865. return ByteString::formatted("JumpNullish {}, null:{} nonnull:{}",
  1866. format_operand("condition"sv, m_condition, executable),
  1867. m_true_target,
  1868. m_false_target);
  1869. }
  1870. #define HANDLE_COMPARISON_OP(op_TitleCase, op_snake_case) \
  1871. ByteString Jump##op_TitleCase::to_byte_string_impl(Bytecode::Executable const& executable) const \
  1872. { \
  1873. return ByteString::formatted("Jump" #op_TitleCase " {}, {}, true:{}, false:{}", \
  1874. format_operand("lhs"sv, m_lhs, executable), \
  1875. format_operand("rhs"sv, m_rhs, executable), \
  1876. m_true_target, \
  1877. m_false_target); \
  1878. }
  1879. JS_ENUMERATE_COMPARISON_OPS(HANDLE_COMPARISON_OP)
  1880. ByteString JumpUndefined::to_byte_string_impl(Bytecode::Executable const& executable) const
  1881. {
  1882. return ByteString::formatted("JumpUndefined {}, undefined:{} defined:{}",
  1883. format_operand("condition"sv, m_condition, executable),
  1884. m_true_target,
  1885. m_false_target);
  1886. }
  1887. static StringView call_type_to_string(CallType type)
  1888. {
  1889. switch (type) {
  1890. case CallType::Call:
  1891. return ""sv;
  1892. case CallType::Construct:
  1893. return " (Construct)"sv;
  1894. case CallType::DirectEval:
  1895. return " (DirectEval)"sv;
  1896. }
  1897. VERIFY_NOT_REACHED();
  1898. }
  1899. ByteString Call::to_byte_string_impl(Bytecode::Executable const& executable) const
  1900. {
  1901. auto type = call_type_to_string(m_type);
  1902. StringBuilder builder;
  1903. builder.appendff("Call{} {}, {}, {}, "sv,
  1904. type,
  1905. format_operand("dst"sv, m_dst, executable),
  1906. format_operand("callee"sv, m_callee, executable),
  1907. format_operand("this"sv, m_this_value, executable));
  1908. builder.append(format_operand_list("args"sv, { m_arguments, m_argument_count }, executable));
  1909. if (m_builtin.has_value()) {
  1910. builder.appendff(", (builtin:{})", m_builtin.value());
  1911. }
  1912. if (m_expression_string.has_value()) {
  1913. builder.appendff(", `{}`", executable.get_string(m_expression_string.value()));
  1914. }
  1915. return builder.to_byte_string();
  1916. }
  1917. ByteString CallWithArgumentArray::to_byte_string_impl(Bytecode::Executable const& executable) const
  1918. {
  1919. auto type = call_type_to_string(m_type);
  1920. StringBuilder builder;
  1921. builder.appendff("CallWithArgumentArray{} {}, {}, {}, {}",
  1922. type,
  1923. format_operand("dst"sv, m_dst, executable),
  1924. format_operand("callee"sv, m_callee, executable),
  1925. format_operand("this"sv, m_this_value, executable),
  1926. format_operand("arguments"sv, m_arguments, executable));
  1927. if (m_expression_string.has_value())
  1928. builder.appendff(" ({})", executable.get_string(m_expression_string.value()));
  1929. return builder.to_byte_string();
  1930. }
  1931. ByteString SuperCallWithArgumentArray::to_byte_string_impl(Bytecode::Executable const& executable) const
  1932. {
  1933. return ByteString::formatted("SuperCallWithArgumentArray {}, {}",
  1934. format_operand("dst"sv, m_dst, executable),
  1935. format_operand("arguments"sv, m_arguments, executable));
  1936. }
  1937. ByteString NewFunction::to_byte_string_impl(Bytecode::Executable const& executable) const
  1938. {
  1939. StringBuilder builder;
  1940. builder.appendff("NewFunction {}",
  1941. format_operand("dst"sv, m_dst, executable));
  1942. if (m_function_node.has_name())
  1943. builder.appendff(" name:{}"sv, m_function_node.name());
  1944. if (m_lhs_name.has_value())
  1945. builder.appendff(" lhs_name:{}"sv, executable.get_identifier(m_lhs_name.value()));
  1946. if (m_home_object.has_value())
  1947. builder.appendff(", {}"sv, format_operand("home_object"sv, m_home_object.value(), executable));
  1948. return builder.to_byte_string();
  1949. }
  1950. ByteString NewClass::to_byte_string_impl(Bytecode::Executable const& executable) const
  1951. {
  1952. StringBuilder builder;
  1953. auto name = m_class_expression.name();
  1954. builder.appendff("NewClass {}",
  1955. format_operand("dst"sv, m_dst, executable));
  1956. if (m_super_class.has_value())
  1957. builder.appendff(", {}", format_operand("super_class"sv, *m_super_class, executable));
  1958. if (!name.is_empty())
  1959. builder.appendff(", {}", name);
  1960. if (m_lhs_name.has_value())
  1961. builder.appendff(", lhs_name:{}"sv, executable.get_identifier(m_lhs_name.value()));
  1962. return builder.to_byte_string();
  1963. }
  1964. ByteString Return::to_byte_string_impl(Bytecode::Executable const& executable) const
  1965. {
  1966. if (m_value.has_value())
  1967. return ByteString::formatted("Return {}", format_operand("value"sv, m_value.value(), executable));
  1968. return "Return";
  1969. }
  1970. ByteString Increment::to_byte_string_impl(Bytecode::Executable const& executable) const
  1971. {
  1972. return ByteString::formatted("Increment {}", format_operand("dst"sv, m_dst, executable));
  1973. }
  1974. ByteString PostfixIncrement::to_byte_string_impl(Bytecode::Executable const& executable) const
  1975. {
  1976. return ByteString::formatted("PostfixIncrement {}, {}",
  1977. format_operand("dst"sv, m_dst, executable),
  1978. format_operand("src"sv, m_src, executable));
  1979. }
  1980. ByteString Decrement::to_byte_string_impl(Bytecode::Executable const& executable) const
  1981. {
  1982. return ByteString::formatted("Decrement {}", format_operand("dst"sv, m_dst, executable));
  1983. }
  1984. ByteString PostfixDecrement::to_byte_string_impl(Bytecode::Executable const& executable) const
  1985. {
  1986. return ByteString::formatted("PostfixDecrement {}, {}",
  1987. format_operand("dst"sv, m_dst, executable),
  1988. format_operand("src"sv, m_src, executable));
  1989. }
  1990. ByteString Throw::to_byte_string_impl(Bytecode::Executable const& executable) const
  1991. {
  1992. return ByteString::formatted("Throw {}",
  1993. format_operand("src"sv, m_src, executable));
  1994. }
  1995. ByteString ThrowIfNotObject::to_byte_string_impl(Bytecode::Executable const& executable) const
  1996. {
  1997. return ByteString::formatted("ThrowIfNotObject {}",
  1998. format_operand("src"sv, m_src, executable));
  1999. }
  2000. ByteString ThrowIfNullish::to_byte_string_impl(Bytecode::Executable const& executable) const
  2001. {
  2002. return ByteString::formatted("ThrowIfNullish {}",
  2003. format_operand("src"sv, m_src, executable));
  2004. }
  2005. ByteString ThrowIfTDZ::to_byte_string_impl(Bytecode::Executable const& executable) const
  2006. {
  2007. return ByteString::formatted("ThrowIfTDZ {}",
  2008. format_operand("src"sv, m_src, executable));
  2009. }
  2010. ByteString EnterUnwindContext::to_byte_string_impl(Bytecode::Executable const&) const
  2011. {
  2012. return ByteString::formatted("EnterUnwindContext entry:{}", m_entry_point);
  2013. }
  2014. ByteString ScheduleJump::to_byte_string_impl(Bytecode::Executable const&) const
  2015. {
  2016. return ByteString::formatted("ScheduleJump {}", m_target);
  2017. }
  2018. ByteString LeaveLexicalEnvironment::to_byte_string_impl(Bytecode::Executable const&) const
  2019. {
  2020. return "LeaveLexicalEnvironment"sv;
  2021. }
  2022. ByteString LeaveUnwindContext::to_byte_string_impl(Bytecode::Executable const&) const
  2023. {
  2024. return "LeaveUnwindContext";
  2025. }
  2026. ByteString ContinuePendingUnwind::to_byte_string_impl(Bytecode::Executable const&) const
  2027. {
  2028. return ByteString::formatted("ContinuePendingUnwind resume:{}", m_resume_target);
  2029. }
  2030. ByteString Yield::to_byte_string_impl(Bytecode::Executable const& executable) const
  2031. {
  2032. if (m_continuation_label.has_value()) {
  2033. return ByteString::formatted("Yield continuation:{}, {}",
  2034. m_continuation_label.value(),
  2035. format_operand("value"sv, m_value, executable));
  2036. }
  2037. return ByteString::formatted("Yield return {}",
  2038. format_operand("value"sv, m_value, executable));
  2039. }
  2040. ByteString Await::to_byte_string_impl(Bytecode::Executable const& executable) const
  2041. {
  2042. return ByteString::formatted("Await {}, continuation:{}",
  2043. format_operand("argument"sv, m_argument, executable),
  2044. m_continuation_label);
  2045. }
  2046. ByteString GetByValue::to_byte_string_impl(Bytecode::Executable const& executable) const
  2047. {
  2048. return ByteString::formatted("GetByValue {}, {}, {}",
  2049. format_operand("dst"sv, m_dst, executable),
  2050. format_operand("base"sv, m_base, executable),
  2051. format_operand("property"sv, m_property, executable));
  2052. }
  2053. ByteString GetByValueWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  2054. {
  2055. return ByteString::formatted("GetByValueWithThis {}, {}, {}",
  2056. format_operand("dst"sv, m_dst, executable),
  2057. format_operand("base"sv, m_base, executable),
  2058. format_operand("property"sv, m_property, executable));
  2059. }
  2060. ByteString PutByValue::to_byte_string_impl(Bytecode::Executable const& executable) const
  2061. {
  2062. auto kind = property_kind_to_string(m_kind);
  2063. return ByteString::formatted("PutByValue {}, {}, {}, kind:{}",
  2064. format_operand("base"sv, m_base, executable),
  2065. format_operand("property"sv, m_property, executable),
  2066. format_operand("src"sv, m_src, executable),
  2067. kind);
  2068. }
  2069. ByteString PutByValueWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  2070. {
  2071. auto kind = property_kind_to_string(m_kind);
  2072. return ByteString::formatted("PutByValueWithThis {}, {}, {}, {}, kind:{}",
  2073. format_operand("base"sv, m_base, executable),
  2074. format_operand("property"sv, m_property, executable),
  2075. format_operand("src"sv, m_src, executable),
  2076. format_operand("this"sv, m_this_value, executable),
  2077. kind);
  2078. }
  2079. ByteString DeleteByValue::to_byte_string_impl(Bytecode::Executable const& executable) const
  2080. {
  2081. return ByteString::formatted("DeleteByValue {}, {}, {}",
  2082. format_operand("dst"sv, dst(), executable),
  2083. format_operand("base"sv, m_base, executable),
  2084. format_operand("property"sv, m_property, executable));
  2085. }
  2086. ByteString DeleteByValueWithThis::to_byte_string_impl(Bytecode::Executable const& executable) const
  2087. {
  2088. return ByteString::formatted("DeleteByValueWithThis {}, {}, {}, {}",
  2089. format_operand("dst"sv, dst(), executable),
  2090. format_operand("base"sv, m_base, executable),
  2091. format_operand("property"sv, m_property, executable),
  2092. format_operand("this"sv, m_this_value, executable));
  2093. }
  2094. ByteString GetIterator::to_byte_string_impl(Executable const& executable) const
  2095. {
  2096. auto hint = m_hint == IteratorHint::Sync ? "sync" : "async";
  2097. return ByteString::formatted("GetIterator {}, {}, hint:{}",
  2098. format_operand("dst"sv, m_dst, executable),
  2099. format_operand("iterable"sv, m_iterable, executable),
  2100. hint);
  2101. }
  2102. ByteString GetMethod::to_byte_string_impl(Bytecode::Executable const& executable) const
  2103. {
  2104. return ByteString::formatted("GetMethod {}, {}, {}",
  2105. format_operand("dst"sv, m_dst, executable),
  2106. format_operand("object"sv, m_object, executable),
  2107. executable.identifier_table->get(m_property));
  2108. }
  2109. ByteString GetObjectPropertyIterator::to_byte_string_impl(Bytecode::Executable const& executable) const
  2110. {
  2111. return ByteString::formatted("GetObjectPropertyIterator {}, {}",
  2112. format_operand("dst"sv, dst(), executable),
  2113. format_operand("object"sv, object(), executable));
  2114. }
  2115. ByteString IteratorClose::to_byte_string_impl(Bytecode::Executable const& executable) const
  2116. {
  2117. if (!m_completion_value.has_value())
  2118. return ByteString::formatted("IteratorClose {}, completion_type={} completion_value=<empty>",
  2119. format_operand("iterator_record"sv, m_iterator_record, executable),
  2120. to_underlying(m_completion_type));
  2121. auto completion_value_string = m_completion_value->to_string_without_side_effects();
  2122. return ByteString::formatted("IteratorClose {}, completion_type={} completion_value={}",
  2123. format_operand("iterator_record"sv, m_iterator_record, executable),
  2124. to_underlying(m_completion_type), completion_value_string);
  2125. }
  2126. ByteString AsyncIteratorClose::to_byte_string_impl(Bytecode::Executable const& executable) const
  2127. {
  2128. if (!m_completion_value.has_value()) {
  2129. return ByteString::formatted("AsyncIteratorClose {}, completion_type:{} completion_value:<empty>",
  2130. format_operand("iterator_record"sv, m_iterator_record, executable),
  2131. to_underlying(m_completion_type));
  2132. }
  2133. return ByteString::formatted("AsyncIteratorClose {}, completion_type:{}, completion_value:{}",
  2134. format_operand("iterator_record"sv, m_iterator_record, executable),
  2135. to_underlying(m_completion_type), m_completion_value);
  2136. }
  2137. ByteString IteratorNext::to_byte_string_impl(Executable const& executable) const
  2138. {
  2139. return ByteString::formatted("IteratorNext {}, {}",
  2140. format_operand("dst"sv, m_dst, executable),
  2141. format_operand("iterator_record"sv, m_iterator_record, executable));
  2142. }
  2143. ByteString ResolveThisBinding::to_byte_string_impl(Bytecode::Executable const& executable) const
  2144. {
  2145. return ByteString::formatted("ResolveThisBinding {}", format_operand("dst"sv, m_dst, executable));
  2146. }
  2147. ByteString ResolveSuperBase::to_byte_string_impl(Bytecode::Executable const& executable) const
  2148. {
  2149. return ByteString::formatted("ResolveSuperBase {}",
  2150. format_operand("dst"sv, m_dst, executable));
  2151. }
  2152. ByteString GetNewTarget::to_byte_string_impl(Bytecode::Executable const& executable) const
  2153. {
  2154. return ByteString::formatted("GetNewTarget {}", format_operand("dst"sv, m_dst, executable));
  2155. }
  2156. ByteString GetImportMeta::to_byte_string_impl(Bytecode::Executable const& executable) const
  2157. {
  2158. return ByteString::formatted("GetImportMeta {}", format_operand("dst"sv, m_dst, executable));
  2159. }
  2160. ByteString TypeofVariable::to_byte_string_impl(Bytecode::Executable const& executable) const
  2161. {
  2162. return ByteString::formatted("TypeofVariable {}, {}",
  2163. format_operand("dst"sv, m_dst, executable),
  2164. executable.identifier_table->get(m_identifier));
  2165. }
  2166. ByteString BlockDeclarationInstantiation::to_byte_string_impl(Bytecode::Executable const&) const
  2167. {
  2168. return "BlockDeclarationInstantiation"sv;
  2169. }
  2170. ByteString ImportCall::to_byte_string_impl(Bytecode::Executable const& executable) const
  2171. {
  2172. return ByteString::formatted("ImportCall {}, {}, {}",
  2173. format_operand("dst"sv, m_dst, executable),
  2174. format_operand("specifier"sv, m_specifier, executable),
  2175. format_operand("options"sv, m_options, executable));
  2176. }
  2177. ByteString Catch::to_byte_string_impl(Bytecode::Executable const& executable) const
  2178. {
  2179. return ByteString::formatted("Catch {}",
  2180. format_operand("dst"sv, m_dst, executable));
  2181. }
  2182. ByteString LeaveFinally::to_byte_string_impl(Bytecode::Executable const&) const
  2183. {
  2184. return ByteString::formatted("LeaveFinally");
  2185. }
  2186. ByteString RestoreScheduledJump::to_byte_string_impl(Bytecode::Executable const&) const
  2187. {
  2188. return ByteString::formatted("RestoreScheduledJump");
  2189. }
  2190. ByteString GetObjectFromIteratorRecord::to_byte_string_impl(Bytecode::Executable const& executable) const
  2191. {
  2192. return ByteString::formatted("GetObjectFromIteratorRecord {}, {}",
  2193. format_operand("object"sv, m_object, executable),
  2194. format_operand("iterator_record"sv, m_iterator_record, executable));
  2195. }
  2196. ByteString GetNextMethodFromIteratorRecord::to_byte_string_impl(Bytecode::Executable const& executable) const
  2197. {
  2198. return ByteString::formatted("GetNextMethodFromIteratorRecord {}, {}",
  2199. format_operand("next_method"sv, m_next_method, executable),
  2200. format_operand("iterator_record"sv, m_iterator_record, executable));
  2201. }
  2202. ByteString End::to_byte_string_impl(Bytecode::Executable const& executable) const
  2203. {
  2204. return ByteString::formatted("End {}", format_operand("value"sv, m_value, executable));
  2205. }
  2206. ByteString Dump::to_byte_string_impl(Bytecode::Executable const& executable) const
  2207. {
  2208. return ByteString::formatted("Dump '{}', {}", m_text,
  2209. format_operand("value"sv, m_value, executable));
  2210. }
  2211. }