VM.cpp 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2021-2022, David Tuin <davidot@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #include <AK/Debug.h>
  9. #include <AK/LexicalPath.h>
  10. #include <AK/ScopeGuard.h>
  11. #include <AK/StringBuilder.h>
  12. #include <LibCore/File.h>
  13. #include <LibJS/Interpreter.h>
  14. #include <LibJS/Runtime/AbstractOperations.h>
  15. #include <LibJS/Runtime/Array.h>
  16. #include <LibJS/Runtime/BoundFunction.h>
  17. #include <LibJS/Runtime/Completion.h>
  18. #include <LibJS/Runtime/ECMAScriptFunctionObject.h>
  19. #include <LibJS/Runtime/Error.h>
  20. #include <LibJS/Runtime/FinalizationRegistry.h>
  21. #include <LibJS/Runtime/FunctionEnvironment.h>
  22. #include <LibJS/Runtime/GlobalObject.h>
  23. #include <LibJS/Runtime/IteratorOperations.h>
  24. #include <LibJS/Runtime/NativeFunction.h>
  25. #include <LibJS/Runtime/PromiseReaction.h>
  26. #include <LibJS/Runtime/Reference.h>
  27. #include <LibJS/Runtime/Symbol.h>
  28. #include <LibJS/Runtime/TemporaryClearException.h>
  29. #include <LibJS/Runtime/VM.h>
  30. #include <LibJS/SourceTextModule.h>
  31. namespace JS {
  32. NonnullRefPtr<VM> VM::create(OwnPtr<CustomData> custom_data)
  33. {
  34. return adopt_ref(*new VM(move(custom_data)));
  35. }
  36. VM::VM(OwnPtr<CustomData> custom_data)
  37. : m_heap(*this)
  38. , m_custom_data(move(custom_data))
  39. {
  40. m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
  41. for (size_t i = 0; i < 128; ++i) {
  42. m_single_ascii_character_strings[i] = m_heap.allocate_without_global_object<PrimitiveString>(String::formatted("{:c}", i));
  43. }
  44. host_resolve_imported_module = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier) {
  45. return resolve_imported_module(move(referencing_script_or_module), specifier);
  46. };
  47. host_import_module_dynamically = [&](ScriptOrModule, ModuleRequest const&, PromiseCapability promise_capability) {
  48. // By default, we throw on dynamic imports this is to prevent arbitrary file access by scripts.
  49. VERIFY(current_realm());
  50. auto& global_object = current_realm()->global_object();
  51. auto* promise = Promise::create(global_object);
  52. // If you are here because you want to enable dynamic module importing make sure it won't be a security problem
  53. // by checking the default implementation of HostImportModuleDynamically and creating your own hook or calling
  54. // vm.enable_default_host_import_module_dynamically_hook().
  55. promise->reject(Error::create(global_object, ErrorType::DynamicImportNotAllowed.message()));
  56. promise->perform_then(
  57. NativeFunction::create(global_object, "", [](auto&, auto&) -> ThrowCompletionOr<Value> {
  58. VERIFY_NOT_REACHED();
  59. }),
  60. NativeFunction::create(global_object, "", [reject = make_handle(promise_capability.reject)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
  61. auto error = vm.argument(0);
  62. // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
  63. MUST(call(global_object, reject.cell(), js_undefined(), error));
  64. // b. Return undefined.
  65. return js_undefined();
  66. }),
  67. {});
  68. };
  69. host_finish_dynamic_import = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability, Promise* promise) {
  70. return finish_dynamic_import(move(referencing_script_or_module), specifier, promise_capability, promise);
  71. };
  72. host_get_import_meta_properties = [&](SourceTextModule const&) -> HashMap<PropertyKey, Value> {
  73. return {};
  74. };
  75. host_finalize_import_meta = [&](Object*, SourceTextModule const&) {
  76. };
  77. #define __JS_ENUMERATE(SymbolName, snake_name) \
  78. m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
  79. JS_ENUMERATE_WELL_KNOWN_SYMBOLS
  80. #undef __JS_ENUMERATE
  81. }
  82. VM::~VM()
  83. {
  84. }
  85. void VM::enable_default_host_import_module_dynamically_hook()
  86. {
  87. host_import_module_dynamically = [&](ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability) {
  88. return import_module_dynamically(move(referencing_script_or_module), specifier, promise_capability);
  89. };
  90. }
  91. Interpreter& VM::interpreter()
  92. {
  93. VERIFY(!m_interpreters.is_empty());
  94. return *m_interpreters.last();
  95. }
  96. Interpreter* VM::interpreter_if_exists()
  97. {
  98. if (m_interpreters.is_empty())
  99. return nullptr;
  100. return m_interpreters.last();
  101. }
  102. void VM::push_interpreter(Interpreter& interpreter)
  103. {
  104. m_interpreters.append(&interpreter);
  105. }
  106. void VM::pop_interpreter(Interpreter& interpreter)
  107. {
  108. VERIFY(!m_interpreters.is_empty());
  109. auto* popped_interpreter = m_interpreters.take_last();
  110. VERIFY(popped_interpreter == &interpreter);
  111. }
  112. VM::InterpreterExecutionScope::InterpreterExecutionScope(Interpreter& interpreter)
  113. : m_interpreter(interpreter)
  114. {
  115. m_interpreter.vm().push_interpreter(m_interpreter);
  116. }
  117. VM::InterpreterExecutionScope::~InterpreterExecutionScope()
  118. {
  119. m_interpreter.vm().pop_interpreter(m_interpreter);
  120. }
  121. void VM::gather_roots(HashTable<Cell*>& roots)
  122. {
  123. roots.set(m_empty_string);
  124. for (auto* string : m_single_ascii_character_strings)
  125. roots.set(string);
  126. roots.set(m_exception);
  127. auto gather_roots_from_execution_context_stack = [&roots](Vector<ExecutionContext*> const& stack) {
  128. for (auto& execution_context : stack) {
  129. if (execution_context->this_value.is_cell())
  130. roots.set(&execution_context->this_value.as_cell());
  131. for (auto& argument : execution_context->arguments) {
  132. if (argument.is_cell())
  133. roots.set(&argument.as_cell());
  134. }
  135. roots.set(execution_context->lexical_environment);
  136. roots.set(execution_context->variable_environment);
  137. roots.set(execution_context->private_environment);
  138. }
  139. };
  140. gather_roots_from_execution_context_stack(m_execution_context_stack);
  141. for (auto& saved_stack : m_saved_execution_context_stacks)
  142. gather_roots_from_execution_context_stack(saved_stack);
  143. #define __JS_ENUMERATE(SymbolName, snake_name) \
  144. roots.set(well_known_symbol_##snake_name());
  145. JS_ENUMERATE_WELL_KNOWN_SYMBOLS
  146. #undef __JS_ENUMERATE
  147. for (auto& symbol : m_global_symbol_map)
  148. roots.set(symbol.value);
  149. for (auto* job : m_promise_jobs)
  150. roots.set(job);
  151. for (auto* finalization_registry : m_finalization_registry_cleanup_jobs)
  152. roots.set(finalization_registry);
  153. }
  154. Symbol* VM::get_global_symbol(const String& description)
  155. {
  156. auto result = m_global_symbol_map.get(description);
  157. if (result.has_value())
  158. return result.value();
  159. auto new_global_symbol = js_symbol(*this, description, true);
  160. m_global_symbol_map.set(description, new_global_symbol);
  161. return new_global_symbol;
  162. }
  163. ThrowCompletionOr<Value> VM::named_evaluation_if_anonymous_function(GlobalObject& global_object, ASTNode const& expression, FlyString const& name)
  164. {
  165. // 8.3.3 Static Semantics: IsAnonymousFunctionDefinition ( expr ), https://tc39.es/ecma262/#sec-isanonymousfunctiondefinition
  166. // And 8.3.5 Runtime Semantics: NamedEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-namedevaluation
  167. if (is<FunctionExpression>(expression)) {
  168. auto& function = static_cast<FunctionExpression const&>(expression);
  169. if (!function.has_name()) {
  170. return function.instantiate_ordinary_function_expression(interpreter(), global_object, name);
  171. }
  172. } else if (is<ClassExpression>(expression)) {
  173. auto& class_expression = static_cast<ClassExpression const&>(expression);
  174. if (!class_expression.has_name()) {
  175. return TRY(class_expression.class_definition_evaluation(interpreter(), global_object, {}, name));
  176. }
  177. }
  178. return TRY(expression.execute(interpreter(), global_object)).release_value();
  179. }
  180. // 13.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation
  181. ThrowCompletionOr<void> VM::destructuring_assignment_evaluation(NonnullRefPtr<BindingPattern> const& target, Value value, GlobalObject& global_object)
  182. {
  183. // Note: DestructuringAssignmentEvaluation is just like BindingInitialization without an environment
  184. // And it allows member expressions. We thus trust the parser to disallow member expressions
  185. // in any non assignment binding and just call BindingInitialization with a nullptr environment
  186. return binding_initialization(target, value, nullptr, global_object);
  187. }
  188. // 8.5.2 Runtime Semantics: BindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-bindinginitialization
  189. ThrowCompletionOr<void> VM::binding_initialization(FlyString const& target, Value value, Environment* environment, GlobalObject& global_object)
  190. {
  191. // 1. Let name be StringValue of Identifier.
  192. // 2. Return ? InitializeBoundName(name, value, environment).
  193. return initialize_bound_name(global_object, target, value, environment);
  194. }
  195. // 8.5.2 Runtime Semantics: BindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-bindinginitialization
  196. ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> const& target, Value value, Environment* environment, GlobalObject& global_object)
  197. {
  198. // BindingPattern : ObjectBindingPattern
  199. if (target->kind == BindingPattern::Kind::Object) {
  200. // 1. Perform ? RequireObjectCoercible(value).
  201. TRY(require_object_coercible(global_object, value));
  202. // 2. Return the result of performing BindingInitialization of ObjectBindingPattern using value and environment as arguments.
  203. // BindingInitialization of ObjectBindingPattern
  204. // 1. Perform ? PropertyBindingInitialization of BindingPropertyList using value and environment as the arguments.
  205. TRY(property_binding_initialization(*target, value, environment, global_object));
  206. // 2. Return NormalCompletion(empty).
  207. return {};
  208. }
  209. // BindingPattern : ArrayBindingPattern
  210. else {
  211. // 1. Let iteratorRecord be ? GetIterator(value).
  212. auto iterator_record = TRY(get_iterator(global_object, value));
  213. // 2. Let result be IteratorBindingInitialization of ArrayBindingPattern with arguments iteratorRecord and environment.
  214. auto result = iterator_binding_initialization(*target, iterator_record, environment, global_object);
  215. // 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result).
  216. if (!iterator_record.done) {
  217. // iterator_close() always returns a Completion, which ThrowCompletionOr will interpret as a throw
  218. // completion. So only return the result of iterator_close() if it is indeed a throw completion.
  219. auto completion = result.is_throw_completion() ? result.release_error() : normal_completion({});
  220. if (completion = iterator_close(global_object, iterator_record, move(completion)); completion.is_error())
  221. return completion.release_error();
  222. }
  223. // 4. Return result.
  224. return result;
  225. }
  226. }
  227. // 13.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-propertydestructuringassignmentevaluation
  228. // 14.3.3.1 Runtime Semantics: PropertyBindingInitialization, https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-propertybindinginitialization
  229. ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object)
  230. {
  231. auto* object = TRY(value.to_object(global_object));
  232. HashTable<PropertyKey> seen_names;
  233. for (auto& property : binding.entries) {
  234. VERIFY(!property.is_elision());
  235. if (property.is_rest) {
  236. Reference assignment_target;
  237. if (auto identifier_ptr = property.name.get_pointer<NonnullRefPtr<Identifier>>()) {
  238. assignment_target = TRY(resolve_binding((*identifier_ptr)->string(), environment));
  239. } else if (auto member_ptr = property.alias.get_pointer<NonnullRefPtr<MemberExpression>>()) {
  240. assignment_target = TRY((*member_ptr)->to_reference(interpreter(), global_object));
  241. } else {
  242. VERIFY_NOT_REACHED();
  243. }
  244. auto* rest_object = Object::create(global_object, global_object.object_prototype());
  245. VERIFY(rest_object);
  246. TRY(rest_object->copy_data_properties(object, seen_names, global_object));
  247. if (!environment)
  248. return assignment_target.put_value(global_object, rest_object);
  249. else
  250. return assignment_target.initialize_referenced_binding(global_object, rest_object);
  251. }
  252. auto name = TRY(property.name.visit(
  253. [&](Empty) -> ThrowCompletionOr<PropertyKey> { VERIFY_NOT_REACHED(); },
  254. [&](NonnullRefPtr<Identifier> const& identifier) -> ThrowCompletionOr<PropertyKey> {
  255. return identifier->string();
  256. },
  257. [&](NonnullRefPtr<Expression> const& expression) -> ThrowCompletionOr<PropertyKey> {
  258. auto result = TRY(expression->execute(interpreter(), global_object)).release_value();
  259. return result.to_property_key(global_object);
  260. }));
  261. seen_names.set(name);
  262. if (property.name.has<NonnullRefPtr<Identifier>>() && property.alias.has<Empty>()) {
  263. // FIXME: this branch and not taking this have a lot in common we might want to unify it more (like it was before).
  264. auto& identifier = *property.name.get<NonnullRefPtr<Identifier>>();
  265. auto reference = TRY(resolve_binding(identifier.string(), environment));
  266. auto value_to_assign = TRY(object->get(name));
  267. if (property.initializer && value_to_assign.is_undefined()) {
  268. value_to_assign = TRY(named_evaluation_if_anonymous_function(global_object, *property.initializer, identifier.string()));
  269. }
  270. if (!environment)
  271. TRY(reference.put_value(global_object, value_to_assign));
  272. else
  273. TRY(reference.initialize_referenced_binding(global_object, value_to_assign));
  274. continue;
  275. }
  276. auto reference_to_assign_to = TRY(property.alias.visit(
  277. [&](Empty) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
  278. [&](NonnullRefPtr<Identifier> const& identifier) -> ThrowCompletionOr<Optional<Reference>> {
  279. return TRY(resolve_binding(identifier->string(), environment));
  280. },
  281. [&](NonnullRefPtr<BindingPattern> const&) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
  282. [&](NonnullRefPtr<MemberExpression> const& member_expression) -> ThrowCompletionOr<Optional<Reference>> {
  283. return TRY(member_expression->to_reference(interpreter(), global_object));
  284. }));
  285. auto value_to_assign = TRY(object->get(name));
  286. if (property.initializer && value_to_assign.is_undefined()) {
  287. if (auto* identifier_ptr = property.alias.get_pointer<NonnullRefPtr<Identifier>>())
  288. value_to_assign = TRY(named_evaluation_if_anonymous_function(global_object, *property.initializer, (*identifier_ptr)->string()));
  289. else
  290. value_to_assign = TRY(property.initializer->execute(interpreter(), global_object)).release_value();
  291. }
  292. if (auto* binding_ptr = property.alias.get_pointer<NonnullRefPtr<BindingPattern>>()) {
  293. TRY(binding_initialization(*binding_ptr, value_to_assign, environment, global_object));
  294. } else {
  295. VERIFY(reference_to_assign_to.has_value());
  296. if (!environment)
  297. TRY(reference_to_assign_to->put_value(global_object, value_to_assign));
  298. else
  299. TRY(reference_to_assign_to->initialize_referenced_binding(global_object, value_to_assign));
  300. }
  301. }
  302. return {};
  303. }
  304. // 13.15.5.5 Runtime Semantics: IteratorDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-iteratordestructuringassignmentevaluation
  305. // 8.5.3 Runtime Semantics: IteratorBindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-iteratorbindinginitialization
  306. ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment, GlobalObject& global_object)
  307. {
  308. // FIXME: this method is nearly identical to destructuring assignment!
  309. for (size_t i = 0; i < binding.entries.size(); i++) {
  310. auto& entry = binding.entries[i];
  311. Value value;
  312. auto assignment_target = TRY(entry.alias.visit(
  313. [&](Empty) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
  314. [&](NonnullRefPtr<Identifier> const& identifier) -> ThrowCompletionOr<Optional<Reference>> {
  315. return TRY(resolve_binding(identifier->string(), environment));
  316. },
  317. [&](NonnullRefPtr<BindingPattern> const&) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
  318. [&](NonnullRefPtr<MemberExpression> const& member_expression) -> ThrowCompletionOr<Optional<Reference>> {
  319. return TRY(member_expression->to_reference(interpreter(), global_object));
  320. }));
  321. // BindingRestElement : ... BindingIdentifier
  322. // BindingRestElement : ... BindingPattern
  323. if (entry.is_rest) {
  324. VERIFY(i == binding.entries.size() - 1);
  325. // 2. Let A be ! ArrayCreate(0).
  326. auto* array = MUST(Array::create(global_object, 0));
  327. // 3. Let n be 0.
  328. // 4. Repeat,
  329. while (true) {
  330. ThrowCompletionOr<Object*> next { nullptr };
  331. // a. If iteratorRecord.[[Done]] is false, then
  332. if (!iterator_record.done) {
  333. // i. Let next be IteratorStep(iteratorRecord).
  334. next = iterator_step(global_object, iterator_record);
  335. // ii. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
  336. // iii. ReturnIfAbrupt(next).
  337. if (next.is_error()) {
  338. iterator_record.done = true;
  339. return next.release_error();
  340. }
  341. // iv. If next is false, set iteratorRecord.[[Done]] to true.
  342. if (!next.value())
  343. iterator_record.done = true;
  344. }
  345. // b. If iteratorRecord.[[Done]] is true, then
  346. if (iterator_record.done) {
  347. // NOTE: Step i. and ii. are handled below.
  348. break;
  349. }
  350. // c. Let nextValue be IteratorValue(next).
  351. auto next_value = iterator_value(global_object, *next.value());
  352. // d. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
  353. // e. ReturnIfAbrupt(nextValue).
  354. if (next_value.is_error()) {
  355. iterator_record.done = true;
  356. return next_value.release_error();
  357. }
  358. // f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(n)), nextValue).
  359. array->indexed_properties().append(next_value.value());
  360. // g. Set n to n + 1.
  361. }
  362. value = array;
  363. }
  364. // SingleNameBinding : BindingIdentifier Initializer[opt]
  365. // BindingElement : BindingPattern Initializer[opt]
  366. else {
  367. // 1. Let v be undefined.
  368. value = js_undefined();
  369. // 2. If iteratorRecord.[[Done]] is false, then
  370. if (!iterator_record.done) {
  371. // a. Let next be IteratorStep(iteratorRecord).
  372. auto next = iterator_step(global_object, iterator_record);
  373. // b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
  374. // c. ReturnIfAbrupt(next).
  375. if (next.is_error()) {
  376. iterator_record.done = true;
  377. return next.release_error();
  378. }
  379. // d. If next is false, set iteratorRecord.[[Done]] to true.
  380. if (!next.value()) {
  381. iterator_record.done = true;
  382. }
  383. // e. Else,
  384. else {
  385. // i. Set v to IteratorValue(next).
  386. auto value_or_error = iterator_value(global_object, *next.value());
  387. // ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true.
  388. // iii. ReturnIfAbrupt(v).
  389. if (value_or_error.is_throw_completion()) {
  390. iterator_record.done = true;
  391. return value_or_error.release_error();
  392. }
  393. value = value_or_error.release_value();
  394. }
  395. }
  396. // NOTE: Step 3. and 4. are handled below.
  397. }
  398. if (value.is_undefined() && entry.initializer) {
  399. VERIFY(!entry.is_rest);
  400. if (auto* identifier_ptr = entry.alias.get_pointer<NonnullRefPtr<Identifier>>())
  401. value = TRY(named_evaluation_if_anonymous_function(global_object, *entry.initializer, (*identifier_ptr)->string()));
  402. else
  403. value = TRY(entry.initializer->execute(interpreter(), global_object)).release_value();
  404. }
  405. if (auto* binding_ptr = entry.alias.get_pointer<NonnullRefPtr<BindingPattern>>()) {
  406. TRY(binding_initialization(*binding_ptr, value, environment, global_object));
  407. } else if (!entry.alias.has<Empty>()) {
  408. VERIFY(assignment_target.has_value());
  409. if (!environment)
  410. TRY(assignment_target->put_value(global_object, value));
  411. else
  412. TRY(assignment_target->initialize_referenced_binding(global_object, value));
  413. }
  414. }
  415. return {};
  416. }
  417. // 9.1.2.1 GetIdentifierReference ( env, name, strict ), https://tc39.es/ecma262/#sec-getidentifierreference
  418. ThrowCompletionOr<Reference> VM::get_identifier_reference(Environment* environment, FlyString name, bool strict, size_t hops)
  419. {
  420. // 1. If env is the value null, then
  421. if (!environment) {
  422. // a. Return the Reference Record { [[Base]]: unresolvable, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]: empty }.
  423. return Reference { Reference::BaseType::Unresolvable, move(name), strict };
  424. }
  425. // 2. Let exists be ? env.HasBinding(name).
  426. Optional<size_t> index;
  427. auto exists = TRY(environment->has_binding(name, &index));
  428. // Note: This is an optimization for looking up the same reference.
  429. Optional<EnvironmentCoordinate> environment_coordinate;
  430. if (index.has_value())
  431. environment_coordinate = EnvironmentCoordinate { .hops = hops, .index = index.value() };
  432. // 3. If exists is true, then
  433. if (exists) {
  434. // a. Return the Reference Record { [[Base]]: env, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]: empty }.
  435. return Reference { *environment, move(name), strict, environment_coordinate };
  436. }
  437. // 4. Else,
  438. else {
  439. // a. Let outer be env.[[OuterEnv]].
  440. // b. Return ? GetIdentifierReference(outer, name, strict).
  441. return get_identifier_reference(environment->outer_environment(), move(name), strict, hops + 1);
  442. }
  443. }
  444. // 9.4.2 ResolveBinding ( name [ , env ] ), https://tc39.es/ecma262/#sec-resolvebinding
  445. ThrowCompletionOr<Reference> VM::resolve_binding(FlyString const& name, Environment* environment)
  446. {
  447. // 1. If env is not present or if env is undefined, then
  448. if (!environment) {
  449. // a. Set env to the running execution context's LexicalEnvironment.
  450. environment = running_execution_context().lexical_environment;
  451. }
  452. // 2. Assert: env is an Environment Record.
  453. VERIFY(environment);
  454. // 3. If the code matching the syntactic production that is being evaluated is contained in strict mode code, let strict be true; else let strict be false.
  455. bool strict = in_strict_mode();
  456. // 4. Return ? GetIdentifierReference(env, name, strict).
  457. return get_identifier_reference(environment, name, strict);
  458. // NOTE: The spec says:
  459. // Note: The result of ResolveBinding is always a Reference Record whose [[ReferencedName]] field is name.
  460. // But this is not actually correct as GetIdentifierReference (or really the methods it calls) can throw.
  461. }
  462. // 7.3.33 InitializeInstanceElements ( O, constructor ), https://tc39.es/ecma262/#sec-initializeinstanceelements
  463. ThrowCompletionOr<void> VM::initialize_instance_elements(Object& object, ECMAScriptFunctionObject& constructor)
  464. {
  465. for (auto& method : constructor.private_methods())
  466. TRY(object.private_method_or_accessor_add(method));
  467. for (auto& field : constructor.fields())
  468. TRY(object.define_field(field.name, field.initializer));
  469. return {};
  470. }
  471. void VM::throw_exception(Exception& exception)
  472. {
  473. set_exception(exception);
  474. }
  475. // 9.4.4 ResolveThisBinding ( ), https://tc39.es/ecma262/#sec-resolvethisbinding
  476. ThrowCompletionOr<Value> VM::resolve_this_binding(GlobalObject& global_object)
  477. {
  478. // 1. Let envRec be GetThisEnvironment().
  479. auto& environment = get_this_environment(*this);
  480. // 2. Return ? envRec.GetThisBinding().
  481. return TRY(environment.get_this_binding(global_object));
  482. }
  483. String VM::join_arguments(size_t start_index) const
  484. {
  485. StringBuilder joined_arguments;
  486. for (size_t i = start_index; i < argument_count(); ++i) {
  487. joined_arguments.append(argument(i).to_string_without_side_effects().characters());
  488. if (i != argument_count() - 1)
  489. joined_arguments.append(' ');
  490. }
  491. return joined_arguments.build();
  492. }
  493. // 9.4.5 GetNewTarget ( ), https://tc39.es/ecma262/#sec-getnewtarget
  494. Value VM::get_new_target()
  495. {
  496. // 1. Let envRec be GetThisEnvironment().
  497. auto& env = get_this_environment(*this);
  498. // 2. Assert: envRec has a [[NewTarget]] field.
  499. // 3. Return envRec.[[NewTarget]].
  500. return verify_cast<FunctionEnvironment>(env).new_target();
  501. }
  502. bool VM::in_strict_mode() const
  503. {
  504. if (execution_context_stack().is_empty())
  505. return false;
  506. return running_execution_context().is_strict_mode;
  507. }
  508. void VM::run_queued_promise_jobs()
  509. {
  510. dbgln_if(PROMISE_DEBUG, "Running queued promise jobs");
  511. // Temporarily get rid of the exception, if any - job functions must be called
  512. // either way, and that can't happen if we already have an exception stored.
  513. TemporaryClearException temporary_clear_exception(*this);
  514. while (!m_promise_jobs.is_empty()) {
  515. auto* job = m_promise_jobs.take_first();
  516. dbgln_if(PROMISE_DEBUG, "Calling promise job function @ {}", job);
  517. // NOTE: If the execution context stack is empty, we make and push a temporary context.
  518. ExecutionContext execution_context(heap());
  519. bool pushed_execution_context = false;
  520. if (m_execution_context_stack.is_empty()) {
  521. static FlyString promise_execution_context_name = "(promise execution context)";
  522. execution_context.function_name = promise_execution_context_name;
  523. // FIXME: Propagate potential failure
  524. MUST(push_execution_context(execution_context, job->global_object()));
  525. pushed_execution_context = true;
  526. }
  527. [[maybe_unused]] auto result = call(job->global_object(), *job, js_undefined());
  528. // This doesn't match the spec, it actually defines that Job Abstract Closures must return
  529. // a normal completion. In reality that's not the case however, and all major engines clear
  530. // exceptions when running Promise jobs. See the commit where these two lines were initially
  531. // added for a much more detailed explanation.
  532. clear_exception();
  533. if (pushed_execution_context)
  534. pop_execution_context();
  535. }
  536. // Ensure no job has created a new exception, they must clean up after themselves.
  537. // If they don't, we help a little (see above) so that this assumption remains valid.
  538. VERIFY(!m_exception);
  539. }
  540. // 9.5.4 HostEnqueuePromiseJob ( job, realm ), https://tc39.es/ecma262/#sec-hostenqueuepromisejob
  541. void VM::enqueue_promise_job(NativeFunction& job)
  542. {
  543. m_promise_jobs.append(&job);
  544. }
  545. void VM::run_queued_finalization_registry_cleanup_jobs()
  546. {
  547. while (!m_finalization_registry_cleanup_jobs.is_empty()) {
  548. auto* registry = m_finalization_registry_cleanup_jobs.take_first();
  549. registry->cleanup();
  550. }
  551. }
  552. // 9.10.4.1 HostEnqueueFinalizationRegistryCleanupJob ( finalizationRegistry ), https://tc39.es/ecma262/#sec-host-cleanup-finalization-registry
  553. void VM::enqueue_finalization_registry_cleanup_job(FinalizationRegistry& registry)
  554. {
  555. m_finalization_registry_cleanup_jobs.append(&registry);
  556. }
  557. // 27.2.1.9 HostPromiseRejectionTracker ( promise, operation ), https://tc39.es/ecma262/#sec-host-promise-rejection-tracker
  558. void VM::promise_rejection_tracker(const Promise& promise, Promise::RejectionOperation operation) const
  559. {
  560. switch (operation) {
  561. case Promise::RejectionOperation::Reject:
  562. // A promise was rejected without any handlers
  563. if (on_promise_unhandled_rejection)
  564. on_promise_unhandled_rejection(promise);
  565. break;
  566. case Promise::RejectionOperation::Handle:
  567. // A handler was added to an already rejected promise
  568. if (on_promise_rejection_handled)
  569. on_promise_rejection_handled(promise);
  570. break;
  571. default:
  572. VERIFY_NOT_REACHED();
  573. }
  574. }
  575. void VM::dump_backtrace() const
  576. {
  577. for (ssize_t i = m_execution_context_stack.size() - 1; i >= 0; --i) {
  578. auto& frame = m_execution_context_stack[i];
  579. if (frame->current_node) {
  580. auto& source_range = frame->current_node->source_range();
  581. dbgln("-> {} @ {}:{},{}", frame->function_name, source_range.filename, source_range.start.line, source_range.start.column);
  582. } else {
  583. dbgln("-> {}", frame->function_name);
  584. }
  585. }
  586. }
  587. VM::CustomData::~CustomData()
  588. {
  589. }
  590. void VM::save_execution_context_stack()
  591. {
  592. m_saved_execution_context_stacks.append(move(m_execution_context_stack));
  593. }
  594. void VM::restore_execution_context_stack()
  595. {
  596. m_execution_context_stack = m_saved_execution_context_stacks.take_last();
  597. }
  598. // 9.4.1 GetActiveScriptOrModule ( ), https://tc39.es/ecma262/#sec-getactivescriptormodule
  599. ScriptOrModule VM::get_active_script_or_module() const
  600. {
  601. // 1. If the execution context stack is empty, return null.
  602. if (m_execution_context_stack.is_empty())
  603. return Empty {};
  604. // 2. Let ec be the topmost execution context on the execution context stack whose ScriptOrModule component is not null.
  605. for (auto i = m_execution_context_stack.size() - 1; i > 0; i--) {
  606. if (!m_execution_context_stack[i]->script_or_module.has<Empty>())
  607. return m_execution_context_stack[i]->script_or_module;
  608. }
  609. // 3. If no such execution context exists, return null. Otherwise, return ec's ScriptOrModule.
  610. // Note: Since it is not empty we have 0 and since we got here all the
  611. // above contexts don't have a non-null ScriptOrModule
  612. return m_execution_context_stack[0]->script_or_module;
  613. }
  614. VM::StoredModule* VM::get_stored_module(ScriptOrModule const&, String const& filepath)
  615. {
  616. // Note the spec says:
  617. // Each time this operation is called with a specific referencingScriptOrModule, specifier pair as arguments
  618. // it must return the same Module Record instance if it completes normally.
  619. // Currently, we ignore the referencing script or module but this might not be correct in all cases.
  620. auto end_or_module = m_loaded_modules.find_if([&](StoredModule const& stored_module) {
  621. return stored_module.filepath == filepath;
  622. });
  623. if (end_or_module.is_end())
  624. return nullptr;
  625. return &(*end_or_module);
  626. }
  627. ThrowCompletionOr<void> VM::link_and_eval_module(Badge<Interpreter>, SourceTextModule& module)
  628. {
  629. return link_and_eval_module(module);
  630. }
  631. ThrowCompletionOr<void> VM::link_and_eval_module(SourceTextModule& module)
  632. {
  633. auto filepath = module.filename();
  634. auto module_or_end = m_loaded_modules.find_if([&](StoredModule const& stored_module) {
  635. return stored_module.module.ptr() == &module;
  636. });
  637. StoredModule* stored_module;
  638. if (module_or_end.is_end()) {
  639. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Warning introducing module via link_and_eval_module {}", module.filename());
  640. if (m_loaded_modules.size() > 0) {
  641. dbgln("Using link_and_eval module as entry point is not allowed if it is not the first module!");
  642. VERIFY_NOT_REACHED();
  643. }
  644. m_loaded_modules.empend(
  645. &module,
  646. module.filename(),
  647. module,
  648. true);
  649. stored_module = &m_loaded_modules.last();
  650. } else {
  651. stored_module = module_or_end.operator->();
  652. if (stored_module->has_once_started_linking) {
  653. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Module already has started linking once {}", module.filename());
  654. return {};
  655. }
  656. stored_module->has_once_started_linking = true;
  657. }
  658. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking module {}", filepath);
  659. auto linked_or_error = module.link(*this);
  660. if (linked_or_error.is_error())
  661. return linked_or_error.throw_completion();
  662. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking passed, now evaluating module {}", filepath);
  663. auto evaluated_or_error = module.evaluate(*this);
  664. VERIFY(!exception());
  665. if (evaluated_or_error.is_error())
  666. return evaluated_or_error.throw_completion();
  667. auto* evaluated_value = evaluated_or_error.value();
  668. run_queued_promise_jobs();
  669. VERIFY(m_promise_jobs.is_empty());
  670. // FIXME: This will break if we start doing promises actually asynchronously.
  671. VERIFY(evaluated_value->state() != Promise::State::Pending);
  672. if (evaluated_value->state() == Promise::State::Rejected) {
  673. VERIFY(!exception());
  674. return JS::throw_completion(evaluated_value->result());
  675. }
  676. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Evaluating passed for module {}", module.filename());
  677. return {};
  678. }
  679. // 16.2.1.7 HostResolveImportedModule ( referencingScriptOrModule, specifier ), https://tc39.es/ecma262/#sec-hostresolveimportedmodule
  680. ThrowCompletionOr<NonnullRefPtr<Module>> VM::resolve_imported_module(ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier)
  681. {
  682. if (!specifier.assertions.is_empty())
  683. return throw_completion<InternalError>(current_realm()->global_object(), ErrorType::NotImplemented, "HostResolveImportedModule with assertions");
  684. // An implementation of HostResolveImportedModule must conform to the following requirements:
  685. // - If it completes normally, the [[Value]] slot of the completion must contain an instance of a concrete subclass of Module Record.
  686. // - If a Module Record corresponding to the pair referencingScriptOrModule, specifier does not exist or cannot be created, an exception must be thrown.
  687. // - Each time this operation is called with a specific referencingScriptOrModule, specifier pair as arguments it must return the same Module Record instance if it completes normally.
  688. StringView base_filename = referencing_script_or_module.visit(
  689. [&](Empty) {
  690. return "."sv;
  691. },
  692. [&](auto* script_or_module) {
  693. return script_or_module->filename();
  694. });
  695. LexicalPath base_path { base_filename };
  696. auto filepath = LexicalPath::absolute_path(base_path.dirname(), specifier.module_specifier);
  697. #if JS_MODULE_DEBUG
  698. String referencing_module_string = referencing_script_or_module.visit(
  699. [&](Empty) -> String {
  700. return ".";
  701. },
  702. [&](auto* script_or_module) {
  703. if constexpr (IsSame<Script*, decltype(script_or_module)>) {
  704. return String::formatted("Script @ {}", script_or_module);
  705. }
  706. return String::formatted("Module @ {}", script_or_module);
  707. });
  708. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] resolve_imported_module({}, {})", referencing_module_string, filepath);
  709. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] resolved {} + {} -> {}", base_path, specifier.module_specifier, filepath);
  710. #endif
  711. auto* loaded_module_or_end = get_stored_module(referencing_script_or_module, filepath);
  712. if (loaded_module_or_end != nullptr) {
  713. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] resolve_imported_module({}) already loaded at {}", filepath, loaded_module_or_end->module.ptr());
  714. return loaded_module_or_end->module;
  715. }
  716. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] reading and parsing module {}", filepath);
  717. auto& global_object = current_realm()->global_object();
  718. auto file_or_error = Core::File::open(filepath, Core::OpenMode::ReadOnly);
  719. if (file_or_error.is_error()) {
  720. return throw_completion<SyntaxError>(global_object, ErrorType::ModuleNotFound, specifier.module_specifier);
  721. }
  722. // FIXME: Don't read the file in one go.
  723. auto file_content = file_or_error.value()->read_all();
  724. StringView content_view { file_content.data(), file_content.size() };
  725. // Note: We treat all files as module, so if a script does not have exports it just runs it.
  726. auto module_or_errors = SourceTextModule::parse(content_view, *current_realm(), filepath);
  727. if (module_or_errors.is_error()) {
  728. VERIFY(module_or_errors.error().size() > 0);
  729. return throw_completion<SyntaxError>(global_object, module_or_errors.error().first().to_string());
  730. }
  731. auto module = module_or_errors.release_value();
  732. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] resolve_imported_module(...) parsed {} to {}", filepath, module.ptr());
  733. // We have to set it here already in case it references itself.
  734. m_loaded_modules.empend(
  735. referencing_script_or_module,
  736. filepath,
  737. module,
  738. false);
  739. return module;
  740. }
  741. // 16.2.1.8 HostImportModuleDynamically ( referencingScriptOrModule, specifier, promiseCapability ), https://tc39.es/ecma262/#sec-hostimportmoduledynamically
  742. void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability)
  743. {
  744. auto& global_object = current_realm()->global_object();
  745. // Success path:
  746. // - At some future time, the host environment must perform FinishDynamicImport(referencingScriptOrModule, specifier, promiseCapability, promise),
  747. // where promise is a Promise resolved with undefined.
  748. // - Any subsequent call to HostResolveImportedModule after FinishDynamicImport has completed,
  749. // given the arguments referencingScriptOrModule and specifier, must complete normally.
  750. // - The completion value of any subsequent call to HostResolveImportedModule after FinishDynamicImport has completed,
  751. // given the arguments referencingScriptOrModule and specifier, must be a module which has already been evaluated,
  752. // i.e. whose Evaluate concrete method has already been called and returned a normal completion.
  753. // Failure path:
  754. // - At some future time, the host environment must perform
  755. // FinishDynamicImport(referencingScriptOrModule, specifier, promiseCapability, promise),
  756. // where promise is a Promise rejected with an error representing the cause of failure.
  757. auto* promise = Promise::create(global_object);
  758. ScopeGuard finish_dynamic_import = [&] {
  759. host_finish_dynamic_import(referencing_script_or_module, specifier, promise_capability, promise);
  760. };
  761. // Generally within ECMA262 we always get a referencing_script_or_moulde. However, ShadowRealm gives an explicit null.
  762. // To get around this is we attempt to get the active script_or_module otherwise we might start loading "random" files from the working directory.
  763. if (referencing_script_or_module.has<Empty>()) {
  764. referencing_script_or_module = get_active_script_or_module();
  765. // If there is no ScriptOrModule in any of the execution contexts
  766. if (referencing_script_or_module.has<Empty>()) {
  767. // Throw an error for now
  768. promise->reject(InternalError::create(global_object, String::formatted(ErrorType::ModuleNotFoundNoReferencingScript.message(), specifier.module_specifier)));
  769. return;
  770. }
  771. }
  772. VERIFY(!exception());
  773. // Note: If host_resolve_imported_module returns a module it has been loaded successfully and the next call in finish_dynamic_import will retrieve it again.
  774. auto module_or_error = host_resolve_imported_module(referencing_script_or_module, specifier);
  775. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] HostImportModuleDynamically(..., {}) -> {}", specifier.module_specifier, module_or_error.is_error() ? "failed" : "passed");
  776. if (module_or_error.is_throw_completion()) {
  777. // Note: We should not leak the exception thrown in host_resolve_imported_module.
  778. clear_exception();
  779. promise->reject(*module_or_error.throw_completion().value());
  780. } else {
  781. // Note: If you are here because this VERIFY is failing overwrite host_import_module_dynamically
  782. // because this is LibJS internal logic which won't always work
  783. auto module = module_or_error.release_value();
  784. VERIFY(is<SourceTextModule>(*module));
  785. auto& source_text_module = static_cast<SourceTextModule&>(*module);
  786. auto evaluated_or_error = link_and_eval_module(source_text_module);
  787. if (evaluated_or_error.is_throw_completion()) {
  788. // Note: Again we don't want to leak the exception from link_and_eval_module.
  789. clear_exception();
  790. promise->reject(*evaluated_or_error.throw_completion().value());
  791. } else {
  792. VERIFY(!exception());
  793. promise->fulfill(js_undefined());
  794. }
  795. }
  796. // It must return NormalCompletion(undefined).
  797. // Note: Just return void always since the resulting value cannot be accessed by user code.
  798. }
  799. // 16.2.1.9 FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, innerPromise ), https://tc39.es/ecma262/#sec-finishdynamicimport
  800. void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, ModuleRequest const& specifier, PromiseCapability promise_capability, Promise* inner_promise)
  801. {
  802. dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] finish_dynamic_import on {}", specifier.module_specifier);
  803. // 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called:
  804. auto fulfilled_closure = [referencing_script_or_module, specifier, promise_capability](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
  805. auto result = vm.argument(0);
  806. // a. Assert: result is undefined.
  807. VERIFY(result.is_undefined());
  808. // b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier).
  809. auto module_record = MUST(vm.host_resolve_imported_module(referencing_script_or_module, specifier));
  810. // c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed.
  811. // Note: If HostResolveImportedModule returns a module evaluate will have been called on it.
  812. // d. Let namespace be GetModuleNamespace(moduleRecord).
  813. auto namespace_ = module_record->get_module_namespace(vm);
  814. VERIFY(!vm.exception());
  815. // e. If namespace is an abrupt completion, then
  816. if (namespace_.is_throw_completion()) {
  817. // i. Perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
  818. MUST(call(global_object, promise_capability.reject, js_undefined(), *namespace_.throw_completion().value()));
  819. }
  820. // f. Else,
  821. else {
  822. // i. Perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
  823. MUST(call(global_object, promise_capability.resolve, js_undefined(), namespace_.release_value()));
  824. }
  825. // g. Return undefined.
  826. return js_undefined();
  827. };
  828. // 2. Let onFulfilled be ! CreateBuiltinFunction(fulfilledClosure, 0, "", « »).
  829. auto* on_fulfilled = NativeFunction::create(current_realm()->global_object(), "", move(fulfilled_closure));
  830. // 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called:
  831. auto rejected_closure = [promise_capability](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
  832. auto error = vm.argument(0);
  833. // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
  834. MUST(call(global_object, promise_capability.reject, js_undefined(), error));
  835. // b. Return undefined.
  836. return js_undefined();
  837. };
  838. // 4. Let onRejected be ! CreateBuiltinFunction(rejectedClosure, 0, "", « »).
  839. auto* on_rejected = NativeFunction::create(current_realm()->global_object(), "", move(rejected_closure));
  840. // 5. Perform ! PerformPromiseThen(innerPromise, onFulfilled, onRejected).
  841. inner_promise->perform_then(on_fulfilled, on_rejected, {});
  842. VERIFY(!exception());
  843. }
  844. }