ProxyObject.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <LibJS/Runtime/Accessor.h>
  27. #include <LibJS/Runtime/Array.h>
  28. #include <LibJS/Runtime/Error.h>
  29. #include <LibJS/Runtime/GlobalObject.h>
  30. #include <LibJS/Runtime/ProxyObject.h>
  31. namespace JS {
  32. bool static is_compatible_property_descriptor(bool is_extensible, PropertyDescriptor new_descriptor, Optional<PropertyDescriptor> current_descriptor_optional)
  33. {
  34. if (!current_descriptor_optional.has_value())
  35. return is_extensible;
  36. auto current_descriptor = current_descriptor_optional.value();
  37. if (new_descriptor.attributes.is_empty() && new_descriptor.value.is_empty() && !new_descriptor.getter && !new_descriptor.setter)
  38. return true;
  39. if (!current_descriptor.attributes.is_configurable()) {
  40. if (new_descriptor.attributes.is_configurable())
  41. return false;
  42. if (new_descriptor.attributes.has_enumerable() && new_descriptor.attributes.is_enumerable() != current_descriptor.attributes.is_enumerable())
  43. return false;
  44. }
  45. if (new_descriptor.is_generic_descriptor())
  46. return true;
  47. if (current_descriptor.is_data_descriptor() != new_descriptor.is_data_descriptor() && !current_descriptor.attributes.is_configurable())
  48. return false;
  49. if (current_descriptor.is_data_descriptor() && new_descriptor.is_data_descriptor() && !current_descriptor.attributes.is_configurable() && !current_descriptor.attributes.is_writable()) {
  50. if (new_descriptor.attributes.is_writable())
  51. return false;
  52. return new_descriptor.value.is_empty() && same_value(new_descriptor.value, current_descriptor.value);
  53. }
  54. return true;
  55. }
  56. ProxyObject* ProxyObject::create(GlobalObject& global_object, Object& target, Object& handler)
  57. {
  58. return global_object.heap().allocate<ProxyObject>(global_object, target, handler, *global_object.proxy_prototype());
  59. }
  60. ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
  61. : Function(prototype)
  62. , m_target(target)
  63. , m_handler(handler)
  64. {
  65. }
  66. ProxyObject::~ProxyObject()
  67. {
  68. }
  69. Object* ProxyObject::prototype()
  70. {
  71. auto& vm = this->vm();
  72. if (m_is_revoked) {
  73. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  74. return nullptr;
  75. }
  76. auto trap = m_handler.get(vm.names.getPrototypeOf);
  77. if (vm.exception())
  78. return nullptr;
  79. if (trap.is_empty() || trap.is_nullish())
  80. return m_target.prototype();
  81. if (!trap.is_function()) {
  82. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "getPrototypeOf");
  83. return nullptr;
  84. }
  85. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target));
  86. if (vm.exception())
  87. return nullptr;
  88. if (!trap_result.is_object() && !trap_result.is_null()) {
  89. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetPrototypeOfReturn);
  90. return nullptr;
  91. }
  92. if (m_target.is_extensible()) {
  93. if (vm.exception())
  94. return nullptr;
  95. if (trap_result.is_null())
  96. return nullptr;
  97. return &trap_result.as_object();
  98. }
  99. auto target_proto = m_target.prototype();
  100. if (vm.exception())
  101. return nullptr;
  102. if (!same_value(trap_result, Value(target_proto))) {
  103. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetPrototypeOfNonExtensible);
  104. return nullptr;
  105. }
  106. return &trap_result.as_object();
  107. }
  108. const Object* ProxyObject::prototype() const
  109. {
  110. auto& vm = this->vm();
  111. if (m_is_revoked) {
  112. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  113. return nullptr;
  114. }
  115. return const_cast<const Object*>(const_cast<ProxyObject*>(this)->prototype());
  116. }
  117. bool ProxyObject::set_prototype(Object* object)
  118. {
  119. auto& vm = this->vm();
  120. if (m_is_revoked) {
  121. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  122. return false;
  123. }
  124. auto trap = m_handler.get(vm.names.setPrototypeOf);
  125. if (vm.exception())
  126. return false;
  127. if (trap.is_empty() || trap.is_nullish())
  128. return m_target.set_prototype(object);
  129. if (!trap.is_function()) {
  130. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "setPrototypeOf");
  131. return false;
  132. }
  133. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object));
  134. if (vm.exception() || !trap_result.to_boolean())
  135. return false;
  136. if (m_target.is_extensible())
  137. return true;
  138. auto* target_proto = m_target.prototype();
  139. if (vm.exception())
  140. return false;
  141. if (!same_value(Value(object), Value(target_proto))) {
  142. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxySetPrototypeOfNonExtensible);
  143. return false;
  144. }
  145. return true;
  146. }
  147. bool ProxyObject::is_extensible() const
  148. {
  149. auto& vm = this->vm();
  150. if (m_is_revoked) {
  151. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  152. return false;
  153. }
  154. auto trap = m_handler.get(vm.names.isExtensible);
  155. if (vm.exception())
  156. return false;
  157. if (trap.is_empty() || trap.is_nullish())
  158. return m_target.is_extensible();
  159. if (!trap.is_function()) {
  160. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "isExtensible");
  161. return {};
  162. }
  163. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target));
  164. if (vm.exception())
  165. return false;
  166. if (trap_result.to_boolean() != m_target.is_extensible()) {
  167. if (!vm.exception())
  168. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyIsExtensibleReturn);
  169. return false;
  170. }
  171. return trap_result.to_boolean();
  172. }
  173. bool ProxyObject::prevent_extensions()
  174. {
  175. auto& vm = this->vm();
  176. if (m_is_revoked) {
  177. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  178. return false;
  179. }
  180. auto trap = m_handler.get(vm.names.preventExtensions);
  181. if (vm.exception())
  182. return false;
  183. if (trap.is_empty() || trap.is_nullish())
  184. return m_target.prevent_extensions();
  185. if (!trap.is_function()) {
  186. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "preventExtensions");
  187. return {};
  188. }
  189. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target));
  190. if (vm.exception())
  191. return false;
  192. if (trap_result.to_boolean() && m_target.is_extensible()) {
  193. if (!vm.exception())
  194. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyPreventExtensionsReturn);
  195. return false;
  196. }
  197. return trap_result.to_boolean();
  198. }
  199. Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const PropertyName& name) const
  200. {
  201. auto& vm = this->vm();
  202. if (m_is_revoked) {
  203. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  204. return {};
  205. }
  206. auto trap = m_handler.get(vm.names.getOwnPropertyDescriptor);
  207. if (vm.exception())
  208. return {};
  209. if (trap.is_empty() || trap.is_nullish())
  210. return m_target.get_own_property_descriptor(name);
  211. if (!trap.is_function()) {
  212. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "getOwnPropertyDescriptor");
  213. return {};
  214. }
  215. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), name.to_value(vm));
  216. if (vm.exception())
  217. return {};
  218. if (!trap_result.is_object() && !trap_result.is_undefined()) {
  219. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetOwnDescriptorReturn);
  220. return {};
  221. }
  222. auto target_desc = m_target.get_own_property_descriptor(name);
  223. if (vm.exception())
  224. return {};
  225. if (trap_result.is_undefined()) {
  226. if (!target_desc.has_value())
  227. return {};
  228. if (!target_desc.value().attributes.is_configurable()) {
  229. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetOwnDescriptorNonConfigurable);
  230. return {};
  231. }
  232. if (!m_target.is_extensible()) {
  233. if (!vm.exception())
  234. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetOwnDescriptorUndefReturn);
  235. return {};
  236. }
  237. return {};
  238. }
  239. auto result_desc = PropertyDescriptor::from_dictionary(vm, trap_result.as_object());
  240. if (vm.exception())
  241. return {};
  242. if (!is_compatible_property_descriptor(m_target.is_extensible(), result_desc, target_desc)) {
  243. if (!vm.exception())
  244. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetOwnDescriptorInvalidDescriptor);
  245. return {};
  246. }
  247. if (!result_desc.attributes.is_configurable() && (!target_desc.has_value() || target_desc.value().attributes.is_configurable())) {
  248. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetOwnDescriptorInvalidNonConfig);
  249. return {};
  250. }
  251. return result_desc;
  252. }
  253. bool ProxyObject::define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions)
  254. {
  255. auto& vm = this->vm();
  256. if (m_is_revoked) {
  257. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  258. return false;
  259. }
  260. auto trap = m_handler.get(vm.names.defineProperty);
  261. if (vm.exception())
  262. return false;
  263. if (trap.is_empty() || trap.is_nullish())
  264. return m_target.define_property(property_name, descriptor, throw_exceptions);
  265. if (!trap.is_function()) {
  266. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "defineProperty");
  267. return false;
  268. }
  269. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(vm), Value(const_cast<Object*>(&descriptor)));
  270. if (vm.exception() || !trap_result.to_boolean())
  271. return false;
  272. auto target_desc = m_target.get_own_property_descriptor(property_name);
  273. if (vm.exception())
  274. return false;
  275. bool setting_config_false = false;
  276. if (descriptor.has_property(vm.names.configurable) && !descriptor.get(vm.names.configurable).to_boolean())
  277. setting_config_false = true;
  278. if (vm.exception())
  279. return false;
  280. if (!target_desc.has_value()) {
  281. if (!m_target.is_extensible()) {
  282. if (!vm.exception())
  283. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyDefinePropNonExtensible);
  284. return false;
  285. }
  286. if (setting_config_false) {
  287. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyDefinePropNonConfigurableNonExisting);
  288. return false;
  289. }
  290. } else {
  291. if (!is_compatible_property_descriptor(m_target.is_extensible(), PropertyDescriptor::from_dictionary(vm, descriptor), target_desc)) {
  292. if (!vm.exception())
  293. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyDefinePropIncompatibleDescriptor);
  294. return false;
  295. }
  296. if (setting_config_false && target_desc.value().attributes.is_configurable()) {
  297. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyDefinePropExistingConfigurable);
  298. return false;
  299. }
  300. }
  301. return true;
  302. }
  303. bool ProxyObject::has_property(const PropertyName& name) const
  304. {
  305. auto& vm = this->vm();
  306. if (m_is_revoked) {
  307. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  308. return false;
  309. }
  310. auto trap = m_handler.get(vm.names.has);
  311. if (vm.exception())
  312. return false;
  313. if (trap.is_empty() || trap.is_nullish())
  314. return m_target.has_property(name);
  315. if (!trap.is_function()) {
  316. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "has");
  317. return false;
  318. }
  319. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), name.to_value(vm));
  320. if (vm.exception())
  321. return false;
  322. if (!trap_result.to_boolean()) {
  323. auto target_desc = m_target.get_own_property_descriptor(name);
  324. if (vm.exception())
  325. return false;
  326. if (target_desc.has_value()) {
  327. if (!target_desc.value().attributes.is_configurable()) {
  328. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyHasExistingNonConfigurable);
  329. return false;
  330. }
  331. if (!m_target.is_extensible()) {
  332. if (!vm.exception())
  333. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyHasExistingNonExtensible);
  334. return false;
  335. }
  336. }
  337. }
  338. return trap_result.to_boolean();
  339. }
  340. Value ProxyObject::get(const PropertyName& name, Value) const
  341. {
  342. auto& vm = this->vm();
  343. if (m_is_revoked) {
  344. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  345. return {};
  346. }
  347. auto trap = m_handler.get(vm.names.get);
  348. if (vm.exception())
  349. return {};
  350. if (trap.is_empty() || trap.is_nullish())
  351. return m_target.get(name);
  352. if (!trap.is_function()) {
  353. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "get");
  354. return {};
  355. }
  356. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), name.to_value(vm), Value(const_cast<ProxyObject*>(this)));
  357. if (vm.exception())
  358. return {};
  359. auto target_desc = m_target.get_own_property_descriptor(name);
  360. if (target_desc.has_value()) {
  361. if (vm.exception())
  362. return {};
  363. if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(trap_result, target_desc.value().value)) {
  364. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetImmutableDataProperty);
  365. return {};
  366. }
  367. if (target_desc.value().is_accessor_descriptor() && target_desc.value().getter == nullptr && !trap_result.is_undefined()) {
  368. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyGetNonConfigurableAccessor);
  369. return {};
  370. }
  371. }
  372. return trap_result;
  373. }
  374. bool ProxyObject::put(const PropertyName& name, Value value, Value)
  375. {
  376. auto& vm = this->vm();
  377. if (m_is_revoked) {
  378. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  379. return false;
  380. }
  381. auto trap = m_handler.get(vm.names.set);
  382. if (vm.exception())
  383. return false;
  384. if (trap.is_empty() || trap.is_nullish())
  385. return m_target.put(name, value);
  386. if (!trap.is_function()) {
  387. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "set");
  388. return false;
  389. }
  390. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), name.to_value(vm), value, Value(const_cast<ProxyObject*>(this)));
  391. if (vm.exception() || !trap_result.to_boolean())
  392. return false;
  393. auto target_desc = m_target.get_own_property_descriptor(name);
  394. if (vm.exception())
  395. return false;
  396. if (target_desc.has_value() && !target_desc.value().attributes.is_configurable()) {
  397. if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(value, target_desc.value().value)) {
  398. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxySetImmutableDataProperty);
  399. return false;
  400. }
  401. if (target_desc.value().is_accessor_descriptor() && !target_desc.value().setter) {
  402. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxySetNonConfigurableAccessor);
  403. }
  404. }
  405. return true;
  406. }
  407. Value ProxyObject::delete_property(const PropertyName& name)
  408. {
  409. auto& vm = this->vm();
  410. if (m_is_revoked) {
  411. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  412. return {};
  413. }
  414. auto trap = m_handler.get(vm.names.deleteProperty);
  415. if (vm.exception())
  416. return {};
  417. if (trap.is_empty() || trap.is_nullish())
  418. return m_target.delete_property(name);
  419. if (!trap.is_function()) {
  420. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "deleteProperty");
  421. return {};
  422. }
  423. auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), name.to_value(vm));
  424. if (vm.exception())
  425. return {};
  426. if (!trap_result.to_boolean())
  427. return Value(false);
  428. auto target_desc = m_target.get_own_property_descriptor(name);
  429. if (vm.exception())
  430. return {};
  431. if (!target_desc.has_value())
  432. return Value(true);
  433. if (!target_desc.value().attributes.is_configurable()) {
  434. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyDeleteNonConfigurable);
  435. return {};
  436. }
  437. return Value(true);
  438. }
  439. void ProxyObject::visit_children(Cell::Visitor& visitor)
  440. {
  441. Function::visit_children(visitor);
  442. visitor.visit(&m_target);
  443. visitor.visit(&m_handler);
  444. }
  445. Value ProxyObject::call()
  446. {
  447. auto& vm = this->vm();
  448. if (!is_function()) {
  449. vm.throw_exception<TypeError>(global_object(), ErrorType::NotAFunction, Value(this).to_string_without_side_effects());
  450. return {};
  451. }
  452. if (m_is_revoked) {
  453. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  454. return {};
  455. }
  456. auto trap = m_handler.get(vm.names.apply);
  457. if (vm.exception())
  458. return {};
  459. if (trap.is_empty() || trap.is_nullish())
  460. return static_cast<Function&>(m_target).call();
  461. if (!trap.is_function()) {
  462. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "apply");
  463. return {};
  464. }
  465. MarkedValueList arguments(heap());
  466. arguments.append(Value(&m_target));
  467. arguments.append(Value(&m_handler));
  468. // FIXME: Pass global object
  469. auto arguments_array = Array::create(global_object());
  470. vm.for_each_argument([&](auto& argument) {
  471. arguments_array->indexed_properties().append(argument);
  472. });
  473. arguments.append(arguments_array);
  474. return vm.call(trap.as_function(), Value(&m_handler), move(arguments));
  475. }
  476. Value ProxyObject::construct(Function& new_target)
  477. {
  478. auto& vm = this->vm();
  479. if (!is_function()) {
  480. vm.throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, Value(this).to_string_without_side_effects());
  481. return {};
  482. }
  483. if (m_is_revoked) {
  484. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
  485. return {};
  486. }
  487. auto trap = m_handler.get(vm.names.construct);
  488. if (vm.exception())
  489. return {};
  490. if (trap.is_empty() || trap.is_nullish())
  491. return static_cast<Function&>(m_target).construct(new_target);
  492. if (!trap.is_function()) {
  493. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "construct");
  494. return {};
  495. }
  496. MarkedValueList arguments(vm.heap());
  497. arguments.append(Value(&m_target));
  498. auto arguments_array = Array::create(global_object());
  499. vm.for_each_argument([&](auto& argument) {
  500. arguments_array->indexed_properties().append(argument);
  501. });
  502. arguments.append(arguments_array);
  503. arguments.append(Value(&new_target));
  504. auto result = vm.call(trap.as_function(), Value(&m_handler), move(arguments));
  505. if (!result.is_object()) {
  506. vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyConstructBadReturnType);
  507. return {};
  508. }
  509. return result;
  510. }
  511. const FlyString& ProxyObject::name() const
  512. {
  513. ASSERT(is_function());
  514. return static_cast<Function&>(m_target).name();
  515. }
  516. LexicalEnvironment* ProxyObject::create_environment()
  517. {
  518. ASSERT(is_function());
  519. return static_cast<Function&>(m_target).create_environment();
  520. }
  521. }