ProxyObject.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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/Interpreter.h>
  27. #include <LibJS/Runtime/Accessor.h>
  28. #include <LibJS/Runtime/Array.h>
  29. #include <LibJS/Runtime/Error.h>
  30. #include <LibJS/Runtime/GlobalObject.h>
  31. #include <LibJS/Runtime/ProxyObject.h>
  32. namespace JS {
  33. bool static is_compatible_property_descriptor(Interpreter& interpreter, bool is_extensible, PropertyDescriptor new_descriptor, Optional<PropertyDescriptor> current_descriptor_optional)
  34. {
  35. if (!current_descriptor_optional.has_value())
  36. return is_extensible;
  37. auto current_descriptor = current_descriptor_optional.value();
  38. if (new_descriptor.attributes.is_empty() && new_descriptor.value.is_empty() && !new_descriptor.getter && !new_descriptor.setter)
  39. return true;
  40. if (!current_descriptor.attributes.is_configurable()) {
  41. if (new_descriptor.attributes.is_configurable())
  42. return false;
  43. if (new_descriptor.attributes.has_enumerable() && new_descriptor.attributes.is_enumerable() != current_descriptor.attributes.is_enumerable())
  44. return false;
  45. }
  46. if (new_descriptor.is_generic_descriptor())
  47. return true;
  48. if (current_descriptor.is_data_descriptor() != new_descriptor.is_data_descriptor() && !current_descriptor.attributes.is_configurable())
  49. return false;
  50. if (current_descriptor.is_data_descriptor() && new_descriptor.is_data_descriptor() && !current_descriptor.attributes.is_configurable() && !current_descriptor.attributes.is_writable()) {
  51. if (new_descriptor.attributes.is_writable())
  52. return false;
  53. return new_descriptor.value.is_empty() && same_value(interpreter, new_descriptor.value, current_descriptor.value);
  54. }
  55. return true;
  56. }
  57. ProxyObject* ProxyObject::create(GlobalObject& global_object, Object& target, Object& handler)
  58. {
  59. return global_object.heap().allocate<ProxyObject>(global_object, target, handler, *global_object.proxy_prototype());
  60. }
  61. ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype)
  62. : Function(prototype)
  63. , m_target(target)
  64. , m_handler(handler)
  65. {
  66. }
  67. ProxyObject::~ProxyObject()
  68. {
  69. }
  70. Object* ProxyObject::prototype()
  71. {
  72. if (m_is_revoked) {
  73. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  74. return nullptr;
  75. }
  76. auto trap = m_handler.get("getPrototypeOf");
  77. if (interpreter().exception())
  78. return nullptr;
  79. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  80. return m_target.prototype();
  81. if (!trap.is_function()) {
  82. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "getPrototypeOf");
  83. return nullptr;
  84. }
  85. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target));
  86. if (interpreter().exception())
  87. return nullptr;
  88. if (!trap_result.is_object() && !trap_result.is_null()) {
  89. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfReturn);
  90. return nullptr;
  91. }
  92. if (m_target.is_extensible()) {
  93. if (interpreter().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 (interpreter().exception())
  101. return nullptr;
  102. if (!same_value(interpreter(), trap_result, Value(target_proto))) {
  103. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfNonExtensible);
  104. return nullptr;
  105. }
  106. return &trap_result.as_object();
  107. }
  108. const Object* ProxyObject::prototype() const
  109. {
  110. if (m_is_revoked) {
  111. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  112. return nullptr;
  113. }
  114. return const_cast<const Object*>(const_cast<ProxyObject*>(this)->prototype());
  115. }
  116. bool ProxyObject::set_prototype(Object* object)
  117. {
  118. if (m_is_revoked) {
  119. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  120. return false;
  121. }
  122. auto trap = m_handler.get("setPrototypeOf");
  123. if (interpreter().exception())
  124. return false;
  125. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  126. return m_target.set_prototype(object);
  127. if (!trap.is_function()) {
  128. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "setPrototypeOf");
  129. return false;
  130. }
  131. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object)).to_boolean();
  132. if (interpreter().exception() || !trap_result)
  133. return false;
  134. if (m_target.is_extensible())
  135. return true;
  136. auto* target_proto = m_target.prototype();
  137. if (interpreter().exception())
  138. return false;
  139. if (!same_value(interpreter(), Value(object), Value(target_proto))) {
  140. interpreter().throw_exception<TypeError>(ErrorType::ProxySetPrototypeOfNonExtensible);
  141. return false;
  142. }
  143. return true;
  144. }
  145. bool ProxyObject::is_extensible() const
  146. {
  147. if (m_is_revoked) {
  148. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  149. return false;
  150. }
  151. auto trap = m_handler.get("isExtensible");
  152. if (interpreter().exception())
  153. return false;
  154. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  155. return m_target.is_extensible();
  156. if (!trap.is_function()) {
  157. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "isExtensible");
  158. return {};
  159. }
  160. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
  161. if (interpreter().exception())
  162. return false;
  163. if (trap_result != m_target.is_extensible()) {
  164. if (!interpreter().exception())
  165. interpreter().throw_exception<TypeError>(ErrorType::ProxyIsExtensibleReturn);
  166. return false;
  167. }
  168. return trap_result;
  169. }
  170. bool ProxyObject::prevent_extensions()
  171. {
  172. if (m_is_revoked) {
  173. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  174. return false;
  175. }
  176. auto trap = m_handler.get("preventExtensions");
  177. if (interpreter().exception())
  178. return false;
  179. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  180. return m_target.prevent_extensions();
  181. if (!trap.is_function()) {
  182. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "preventExtensions");
  183. return {};
  184. }
  185. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
  186. if (interpreter().exception())
  187. return false;
  188. if (trap_result && m_target.is_extensible()) {
  189. if (!interpreter().exception())
  190. interpreter().throw_exception<TypeError>(ErrorType::ProxyPreventExtensionsReturn);
  191. return false;
  192. }
  193. return trap_result;
  194. }
  195. Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const PropertyName& name) const
  196. {
  197. if (m_is_revoked) {
  198. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  199. return {};
  200. }
  201. auto trap = m_handler.get("getOwnPropertyDescriptor");
  202. if (interpreter().exception())
  203. return {};
  204. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  205. return m_target.get_own_property_descriptor(name);
  206. if (!trap.is_function()) {
  207. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "getOwnPropertyDescriptor");
  208. return {};
  209. }
  210. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()));
  211. if (interpreter().exception())
  212. return {};
  213. if (!trap_result.is_object() && !trap_result.is_undefined()) {
  214. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorReturn);
  215. return {};
  216. }
  217. auto target_desc = m_target.get_own_property_descriptor(name);
  218. if (interpreter().exception())
  219. return {};
  220. if (trap_result.is_undefined()) {
  221. if (!target_desc.has_value())
  222. return {};
  223. if (!target_desc.value().attributes.is_configurable()) {
  224. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorNonConfigurable);
  225. return {};
  226. }
  227. if (!m_target.is_extensible()) {
  228. if (!interpreter().exception())
  229. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorUndefReturn);
  230. return {};
  231. }
  232. return {};
  233. }
  234. auto result_desc = PropertyDescriptor::from_dictionary(interpreter(), trap_result.as_object());
  235. if (interpreter().exception())
  236. return {};
  237. if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), result_desc, target_desc)) {
  238. if (!interpreter().exception())
  239. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorInvalidDescriptor);
  240. return {};
  241. }
  242. if (!result_desc.attributes.is_configurable() && (!target_desc.has_value() || target_desc.value().attributes.is_configurable())) {
  243. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorInvalidNonConfig);
  244. return {};
  245. }
  246. return result_desc;
  247. }
  248. bool ProxyObject::define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions)
  249. {
  250. if (m_is_revoked) {
  251. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  252. return false;
  253. }
  254. auto trap = m_handler.get("defineProperty");
  255. if (interpreter().exception())
  256. return false;
  257. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  258. return m_target.define_property(property_name, descriptor, throw_exceptions);
  259. if (!trap.is_function()) {
  260. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "defineProperty");
  261. return false;
  262. }
  263. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(interpreter()), Value(const_cast<Object*>(&descriptor))).to_boolean();
  264. if (interpreter().exception() || !trap_result)
  265. return false;
  266. auto target_desc = m_target.get_own_property_descriptor(property_name);
  267. if (interpreter().exception())
  268. return false;
  269. bool setting_config_false = false;
  270. if (descriptor.has_property("configurable") && !descriptor.get("configurable").to_boolean())
  271. setting_config_false = true;
  272. if (interpreter().exception())
  273. return false;
  274. if (!target_desc.has_value()) {
  275. if (!m_target.is_extensible()) {
  276. if (!interpreter().exception())
  277. interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropNonExtensible);
  278. return false;
  279. }
  280. if (setting_config_false) {
  281. interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropNonConfigurableNonExisting);
  282. return false;
  283. }
  284. } else {
  285. if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), PropertyDescriptor::from_dictionary(interpreter(), descriptor), target_desc)) {
  286. if (!interpreter().exception())
  287. interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropIncompatibleDescriptor);
  288. return false;
  289. }
  290. if (setting_config_false && target_desc.value().attributes.is_configurable()) {
  291. interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropExistingConfigurable);
  292. return false;
  293. }
  294. }
  295. return true;
  296. }
  297. bool ProxyObject::has_property(const PropertyName& name) const
  298. {
  299. if (m_is_revoked) {
  300. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  301. return false;
  302. }
  303. auto trap = m_handler.get("has");
  304. if (interpreter().exception())
  305. return false;
  306. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  307. return m_target.has_property(name);
  308. if (!trap.is_function()) {
  309. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "has");
  310. return false;
  311. }
  312. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean();
  313. if (interpreter().exception())
  314. return false;
  315. if (!trap_result) {
  316. auto target_desc = m_target.get_own_property_descriptor(name);
  317. if (interpreter().exception())
  318. return false;
  319. if (target_desc.has_value()) {
  320. if (!target_desc.value().attributes.is_configurable()) {
  321. interpreter().throw_exception<TypeError>(ErrorType::ProxyHasExistingNonConfigurable);
  322. return false;
  323. }
  324. if (!m_target.is_extensible()) {
  325. if (!interpreter().exception())
  326. interpreter().throw_exception<TypeError>(ErrorType::ProxyHasExistingNonExtensible);
  327. return false;
  328. }
  329. }
  330. }
  331. return trap_result;
  332. }
  333. Value ProxyObject::get(const PropertyName& name, Value) const
  334. {
  335. if (m_is_revoked) {
  336. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  337. return {};
  338. }
  339. auto trap = m_handler.get("get");
  340. if (interpreter().exception())
  341. return {};
  342. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  343. return m_target.get(name);
  344. if (!trap.is_function()) {
  345. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "get");
  346. return {};
  347. }
  348. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), Value(const_cast<ProxyObject*>(this)));
  349. if (interpreter().exception())
  350. return {};
  351. auto target_desc = m_target.get_own_property_descriptor(name);
  352. if (target_desc.has_value()) {
  353. if (interpreter().exception())
  354. return {};
  355. if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), trap_result, target_desc.value().value)) {
  356. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetImmutableDataProperty);
  357. return {};
  358. }
  359. if (target_desc.value().is_accessor_descriptor() && target_desc.value().getter == nullptr && !trap_result.is_undefined()) {
  360. interpreter().throw_exception<TypeError>(ErrorType::ProxyGetNonConfigurableAccessor);
  361. return {};
  362. }
  363. }
  364. return trap_result;
  365. }
  366. bool ProxyObject::put(const PropertyName& name, Value value, Value)
  367. {
  368. if (m_is_revoked) {
  369. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  370. return false;
  371. }
  372. auto trap = m_handler.get("set");
  373. if (interpreter().exception())
  374. return false;
  375. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  376. return m_target.put(name, value);
  377. if (!trap.is_function()) {
  378. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "set");
  379. return false;
  380. }
  381. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), value, Value(const_cast<ProxyObject*>(this))).to_boolean();
  382. if (interpreter().exception() || !trap_result)
  383. return false;
  384. auto target_desc = m_target.get_own_property_descriptor(name);
  385. if (interpreter().exception())
  386. return false;
  387. if (target_desc.has_value() && !target_desc.value().attributes.is_configurable()) {
  388. if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), value, target_desc.value().value)) {
  389. interpreter().throw_exception<TypeError>(ErrorType::ProxySetImmutableDataProperty);
  390. return false;
  391. }
  392. if (target_desc.value().is_accessor_descriptor() && !target_desc.value().setter) {
  393. interpreter().throw_exception<TypeError>(ErrorType::ProxySetNonConfigurableAccessor);
  394. }
  395. }
  396. return true;
  397. }
  398. Value ProxyObject::delete_property(const PropertyName& name)
  399. {
  400. if (m_is_revoked) {
  401. interpreter().throw_exception<TypeError>(ErrorType::ProxyRevoked);
  402. return {};
  403. }
  404. auto trap = m_handler.get("deleteProperty");
  405. if (interpreter().exception())
  406. return {};
  407. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  408. return m_target.delete_property(name);
  409. if (!trap.is_function()) {
  410. interpreter().throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "deleteProperty");
  411. return {};
  412. }
  413. auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean();
  414. if (interpreter().exception())
  415. return {};
  416. if (!trap_result)
  417. return Value(false);
  418. auto target_desc = m_target.get_own_property_descriptor(name);
  419. if (interpreter().exception())
  420. return {};
  421. if (!target_desc.has_value())
  422. return Value(true);
  423. if (!target_desc.value().attributes.is_configurable()) {
  424. interpreter().throw_exception<TypeError>(ErrorType::ProxyDeleteNonConfigurable);
  425. return {};
  426. }
  427. return Value(true);
  428. }
  429. void ProxyObject::visit_children(Cell::Visitor& visitor)
  430. {
  431. Function::visit_children(visitor);
  432. visitor.visit(&m_target);
  433. visitor.visit(&m_handler);
  434. }
  435. Value ProxyObject::call(Interpreter& interpreter)
  436. {
  437. if (!is_function()) {
  438. interpreter.throw_exception<TypeError>(ErrorType::NotAFunction, Value(this).to_string_without_side_effects().characters());
  439. return {};
  440. }
  441. if (m_is_revoked) {
  442. interpreter.throw_exception<TypeError>(ErrorType::ProxyRevoked);
  443. return {};
  444. }
  445. auto trap = m_handler.get("apply");
  446. if (interpreter.exception())
  447. return {};
  448. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  449. return static_cast<Function&>(m_target).call(interpreter);
  450. if (!trap.is_function()) {
  451. interpreter.throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "apply");
  452. return {};
  453. }
  454. MarkedValueList arguments(interpreter.heap());
  455. arguments.append(Value(&m_target));
  456. arguments.append(Value(&m_handler));
  457. // FIXME: Pass global object
  458. auto arguments_array = Array::create(interpreter.global_object());
  459. interpreter.for_each_argument([&](auto& argument) {
  460. arguments_array->indexed_properties().append(argument);
  461. });
  462. arguments.append(arguments_array);
  463. return interpreter.call(trap.as_function(), Value(&m_handler), move(arguments));
  464. }
  465. Value ProxyObject::construct(Interpreter& interpreter, Function& new_target)
  466. {
  467. if (!is_function()) {
  468. interpreter.throw_exception<TypeError>(ErrorType::NotAConstructor, Value(this).to_string_without_side_effects().characters());
  469. return {};
  470. }
  471. if (m_is_revoked) {
  472. interpreter.throw_exception<TypeError>(ErrorType::ProxyRevoked);
  473. return {};
  474. }
  475. auto trap = m_handler.get("construct");
  476. if (interpreter.exception())
  477. return {};
  478. if (trap.is_empty() || trap.is_undefined() || trap.is_null())
  479. return static_cast<Function&>(m_target).construct(interpreter, new_target);
  480. if (!trap.is_function()) {
  481. interpreter.throw_exception<TypeError>(ErrorType::ProxyInvalidTrap, "construct");
  482. return {};
  483. }
  484. MarkedValueList arguments(interpreter.heap());
  485. arguments.append(Value(&m_target));
  486. auto arguments_array = Array::create(interpreter.global_object());
  487. interpreter.for_each_argument([&](auto& argument) {
  488. arguments_array->indexed_properties().append(argument);
  489. });
  490. arguments.append(arguments_array);
  491. arguments.append(Value(&new_target));
  492. auto result = interpreter.call(trap.as_function(), Value(&m_handler), move(arguments));
  493. if (!result.is_object()) {
  494. interpreter.throw_exception<TypeError>(ErrorType::ProxyConstructBadReturnType);
  495. return {};
  496. }
  497. return result;
  498. }
  499. const FlyString& ProxyObject::name() const
  500. {
  501. ASSERT(is_function());
  502. return static_cast<Function&>(m_target).name();
  503. }
  504. LexicalEnvironment* ProxyObject::create_environment()
  505. {
  506. ASSERT(is_function());
  507. return static_cast<Function&>(m_target).create_environment();
  508. }
  509. }