Object.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/String.h>
  8. #include <AK/TemporaryChange.h>
  9. #include <LibJS/Heap/Heap.h>
  10. #include <LibJS/Interpreter.h>
  11. #include <LibJS/Runtime/AbstractOperations.h>
  12. #include <LibJS/Runtime/Accessor.h>
  13. #include <LibJS/Runtime/Array.h>
  14. #include <LibJS/Runtime/Error.h>
  15. #include <LibJS/Runtime/GlobalObject.h>
  16. #include <LibJS/Runtime/NativeFunction.h>
  17. #include <LibJS/Runtime/Object.h>
  18. #include <LibJS/Runtime/PropertyDescriptor.h>
  19. #include <LibJS/Runtime/ProxyObject.h>
  20. #include <LibJS/Runtime/Shape.h>
  21. #include <LibJS/Runtime/TemporaryClearException.h>
  22. #include <LibJS/Runtime/Value.h>
  23. namespace JS {
  24. // 10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinaryobjectcreate
  25. Object* Object::create(GlobalObject& global_object, Object* prototype)
  26. {
  27. if (!prototype)
  28. return global_object.heap().allocate<Object>(global_object, *global_object.empty_object_shape());
  29. else if (prototype == global_object.object_prototype())
  30. return global_object.heap().allocate<Object>(global_object, *global_object.new_object_shape());
  31. else
  32. return global_object.heap().allocate<Object>(global_object, *prototype);
  33. }
  34. Object::Object(GlobalObjectTag)
  35. {
  36. // This is the global object
  37. m_shape = heap().allocate_without_global_object<Shape>(*this);
  38. }
  39. Object::Object(ConstructWithoutPrototypeTag, GlobalObject& global_object)
  40. {
  41. m_shape = heap().allocate_without_global_object<Shape>(global_object);
  42. }
  43. Object::Object(Object& prototype)
  44. {
  45. m_shape = prototype.global_object().empty_object_shape();
  46. auto success = internal_set_prototype_of(&prototype);
  47. VERIFY(success);
  48. }
  49. Object::Object(Shape& shape)
  50. : m_shape(&shape)
  51. {
  52. m_storage.resize(shape.property_count());
  53. }
  54. void Object::initialize(GlobalObject&)
  55. {
  56. }
  57. Object::~Object()
  58. {
  59. }
  60. // 7.2 Testing and Comparison Operations, https://tc39.es/ecma262/#sec-testing-and-comparison-operations
  61. // 7.2.5 IsExtensible ( O ), https://tc39.es/ecma262/#sec-isextensible-o
  62. bool Object::is_extensible() const
  63. {
  64. return internal_is_extensible();
  65. }
  66. // 7.3 Operations on Objects, https://tc39.es/ecma262/#sec-operations-on-objects
  67. // 7.3.2 Get ( O, P ), https://tc39.es/ecma262/#sec-get-o-p
  68. Value Object::get(PropertyName const& property_name) const
  69. {
  70. // 1. Assert: Type(O) is Object.
  71. // 2. Assert: IsPropertyKey(P) is true.
  72. VERIFY(property_name.is_valid());
  73. // 3. Return ? O.[[Get]](P, O).
  74. return internal_get(property_name, this);
  75. }
  76. // 7.3.3 GetV ( V, P ) is defined as Value::get().
  77. // 7.3.4 Set ( O, P, V, Throw ), https://tc39.es/ecma262/#sec-set-o-p-v-throw
  78. bool Object::set(PropertyName const& property_name, Value value, bool throw_exceptions)
  79. {
  80. VERIFY(!value.is_empty());
  81. auto& vm = this->vm();
  82. // 1. Assert: Type(O) is Object.
  83. // 2. Assert: IsPropertyKey(P) is true.
  84. VERIFY(property_name.is_valid());
  85. // 3. Assert: Type(Throw) is Boolean.
  86. // 4. Let success be ? O.[[Set]](P, V, O).
  87. auto success = internal_set(property_name, value, this);
  88. if (vm.exception())
  89. return {};
  90. // 5. If success is false and Throw is true, throw a TypeError exception.
  91. if (!success && throw_exceptions) {
  92. // FIXME: Improve/contextualize error message
  93. vm.throw_exception<TypeError>(global_object(), ErrorType::ObjectSetReturnedFalse);
  94. return {};
  95. }
  96. // 6. Return success.
  97. return success;
  98. }
  99. // 7.3.5 CreateDataProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createdataproperty
  100. bool Object::create_data_property(PropertyName const& property_name, Value value)
  101. {
  102. // 1. Assert: Type(O) is Object.
  103. // 2. Assert: IsPropertyKey(P) is true.
  104. VERIFY(property_name.is_valid());
  105. // 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
  106. auto new_descriptor = PropertyDescriptor {
  107. .value = value,
  108. .writable = true,
  109. .enumerable = true,
  110. .configurable = true,
  111. };
  112. // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
  113. return internal_define_own_property(property_name, new_descriptor);
  114. }
  115. // 7.3.6 CreateMethodProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createmethodproperty
  116. bool Object::create_method_property(PropertyName const& property_name, Value value)
  117. {
  118. VERIFY(!value.is_empty());
  119. // 1. Assert: Type(O) is Object.
  120. // 2. Assert: IsPropertyKey(P) is true.
  121. VERIFY(property_name.is_valid());
  122. // 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
  123. auto new_descriptor = PropertyDescriptor {
  124. .value = value,
  125. .writable = true,
  126. .enumerable = false,
  127. .configurable = true,
  128. };
  129. // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
  130. return internal_define_own_property(property_name, new_descriptor);
  131. }
  132. // 7.3.7 CreateDataPropertyOrThrow ( O, P, V ), https://tc39.es/ecma262/#sec-createdatapropertyorthrow
  133. bool Object::create_data_property_or_throw(PropertyName const& property_name, Value value)
  134. {
  135. VERIFY(!value.is_empty());
  136. auto& vm = this->vm();
  137. // 1. Assert: Type(O) is Object.
  138. // 2. Assert: IsPropertyKey(P) is true.
  139. VERIFY(property_name.is_valid());
  140. // 3. Let success be ? CreateDataProperty(O, P, V).
  141. auto success = create_data_property(property_name, value);
  142. if (vm.exception())
  143. return {};
  144. // 4. If success is false, throw a TypeError exception.
  145. if (!success) {
  146. // FIXME: Improve/contextualize error message
  147. vm.throw_exception<TypeError>(global_object(), ErrorType::ObjectDefineOwnPropertyReturnedFalse);
  148. return {};
  149. }
  150. // 5. Return success.
  151. return success;
  152. }
  153. // 7.3.6 CreateNonEnumerableDataPropertyOrThrow ( O, P, V ), https://tc39.es/proposal-error-cause/#sec-createnonenumerabledatapropertyorthrow
  154. bool Object::create_non_enumerable_data_property_or_throw(PropertyName const& property_name, Value value)
  155. {
  156. VERIFY(!value.is_empty());
  157. VERIFY(property_name.is_valid());
  158. // 1. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
  159. auto new_description = PropertyDescriptor { .value = value, .writable = true, .enumerable = false, .configurable = true };
  160. // 2. Return ? DefinePropertyOrThrow(O, P, newDesc).
  161. return define_property_or_throw(property_name, new_description);
  162. }
  163. // 7.3.8 DefinePropertyOrThrow ( O, P, desc ), https://tc39.es/ecma262/#sec-definepropertyorthrow
  164. bool Object::define_property_or_throw(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
  165. {
  166. auto& vm = this->vm();
  167. // 1. Assert: Type(O) is Object.
  168. // 2. Assert: IsPropertyKey(P) is true.
  169. VERIFY(property_name.is_valid());
  170. // 3. Let success be ? O.[[DefineOwnProperty]](P, desc).
  171. auto success = internal_define_own_property(property_name, property_descriptor);
  172. if (vm.exception())
  173. return {};
  174. // 4. If success is false, throw a TypeError exception.
  175. if (!success) {
  176. // FIXME: Improve/contextualize error message
  177. vm.throw_exception<TypeError>(global_object(), ErrorType::ObjectDefineOwnPropertyReturnedFalse);
  178. return {};
  179. }
  180. // 5. Return success.
  181. return success;
  182. }
  183. // 7.3.9 DeletePropertyOrThrow ( O, P ), https://tc39.es/ecma262/#sec-deletepropertyorthrow
  184. bool Object::delete_property_or_throw(PropertyName const& property_name)
  185. {
  186. auto& vm = this->vm();
  187. // 1. Assert: Type(O) is Object.
  188. // 2. Assert: IsPropertyKey(P) is true.
  189. VERIFY(property_name.is_valid());
  190. // 3. Let success be ? O.[[Delete]](P).
  191. auto success = internal_delete(property_name);
  192. if (vm.exception())
  193. return {};
  194. // 4. If success is false, throw a TypeError exception.
  195. if (!success) {
  196. // FIXME: Improve/contextualize error message
  197. vm.throw_exception<TypeError>(global_object(), ErrorType::ObjectDeleteReturnedFalse);
  198. return {};
  199. }
  200. // 5. Return success.
  201. return success;
  202. }
  203. // 7.3.11 HasProperty ( O, P ), https://tc39.es/ecma262/#sec-hasproperty
  204. bool Object::has_property(PropertyName const& property_name) const
  205. {
  206. // 1. Assert: Type(O) is Object.
  207. // 2. Assert: IsPropertyKey(P) is true.
  208. VERIFY(property_name.is_valid());
  209. // 3. Return ? O.[[HasProperty]](P).
  210. return internal_has_property(property_name);
  211. }
  212. // 7.3.12 HasOwnProperty ( O, P ), https://tc39.es/ecma262/#sec-hasownproperty
  213. bool Object::has_own_property(PropertyName const& property_name) const
  214. {
  215. auto& vm = this->vm();
  216. // 1. Assert: Type(O) is Object.
  217. // 2. Assert: IsPropertyKey(P) is true.
  218. VERIFY(property_name.is_valid());
  219. // 3. Let desc be ? O.[[GetOwnProperty]](P).
  220. auto descriptor = internal_get_own_property(property_name);
  221. if (vm.exception())
  222. return {};
  223. // 4. If desc is undefined, return false.
  224. if (!descriptor.has_value())
  225. return false;
  226. // 5. Return true.
  227. return true;
  228. }
  229. // 7.3.15 SetIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-setintegritylevel
  230. bool Object::set_integrity_level(IntegrityLevel level)
  231. {
  232. auto& vm = this->vm();
  233. auto& global_object = this->global_object();
  234. // 1. Assert: Type(O) is Object.
  235. // 2. Assert: level is either sealed or frozen.
  236. VERIFY(level == IntegrityLevel::Sealed || level == IntegrityLevel::Frozen);
  237. // 3. Let status be ? O.[[PreventExtensions]]().
  238. auto status = internal_prevent_extensions();
  239. if (vm.exception())
  240. return {};
  241. // 4. If status is false, return false.
  242. if (!status)
  243. return false;
  244. // 5. Let keys be ? O.[[OwnPropertyKeys]]().
  245. auto keys = internal_own_property_keys();
  246. if (vm.exception())
  247. return {};
  248. // 6. If level is sealed, then
  249. if (level == IntegrityLevel::Sealed) {
  250. // a. For each element k of keys, do
  251. for (auto& key : keys) {
  252. auto property_name = PropertyName::from_value(global_object, key);
  253. // i. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
  254. define_property_or_throw(property_name, { .configurable = false });
  255. if (vm.exception())
  256. return {};
  257. }
  258. }
  259. // 7. Else,
  260. else {
  261. // a. Assert: level is frozen.
  262. // b. For each element k of keys, do
  263. for (auto& key : keys) {
  264. auto property_name = PropertyName::from_value(global_object, key);
  265. // i. Let currentDesc be ? O.[[GetOwnProperty]](k).
  266. auto current_descriptor = internal_get_own_property(property_name);
  267. if (vm.exception())
  268. return {};
  269. // ii. If currentDesc is not undefined, then
  270. if (!current_descriptor.has_value())
  271. continue;
  272. PropertyDescriptor descriptor;
  273. // 1. If IsAccessorDescriptor(currentDesc) is true, then
  274. if (current_descriptor->is_accessor_descriptor()) {
  275. // a. Let desc be the PropertyDescriptor { [[Configurable]]: false }.
  276. descriptor = { .configurable = false };
  277. }
  278. // 2. Else,
  279. else {
  280. // a. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
  281. descriptor = { .writable = false, .configurable = false };
  282. }
  283. // 3. Perform ? DefinePropertyOrThrow(O, k, desc).
  284. define_property_or_throw(property_name, descriptor);
  285. if (vm.exception())
  286. return {};
  287. }
  288. }
  289. // 8. Return true.
  290. return true;
  291. }
  292. // 7.3.16 TestIntegrityLevel ( O, level ), https://tc39.es/ecma262/#sec-testintegritylevel
  293. bool Object::test_integrity_level(IntegrityLevel level) const
  294. {
  295. auto& vm = this->vm();
  296. // 1. Assert: Type(O) is Object.
  297. // 2. Assert: level is either sealed or frozen.
  298. VERIFY(level == IntegrityLevel::Sealed || level == IntegrityLevel::Frozen);
  299. // 3. Let extensible be ? IsExtensible(O).
  300. auto extensible = is_extensible();
  301. if (vm.exception())
  302. return {};
  303. // 4. If extensible is true, return false.
  304. // 5. NOTE: If the object is extensible, none of its properties are examined.
  305. if (extensible)
  306. return false;
  307. // 6. Let keys be ? O.[[OwnPropertyKeys]]().
  308. auto keys = internal_own_property_keys();
  309. if (vm.exception())
  310. return {};
  311. // 7. For each element k of keys, do
  312. for (auto& key : keys) {
  313. auto property_name = PropertyName::from_value(global_object(), key);
  314. // a. Let currentDesc be ? O.[[GetOwnProperty]](k).
  315. auto current_descriptor = internal_get_own_property(property_name);
  316. if (vm.exception())
  317. return {};
  318. // b. If currentDesc is not undefined, then
  319. if (!current_descriptor.has_value())
  320. continue;
  321. // i. If currentDesc.[[Configurable]] is true, return false.
  322. if (*current_descriptor->configurable)
  323. return false;
  324. // ii. If level is frozen and IsDataDescriptor(currentDesc) is true, then
  325. if (level == IntegrityLevel::Frozen && current_descriptor->is_data_descriptor()) {
  326. // 1. If currentDesc.[[Writable]] is true, return false.
  327. if (*current_descriptor->writable)
  328. return false;
  329. }
  330. }
  331. // 8. Return true.
  332. return true;
  333. }
  334. // 7.3.23 EnumerableOwnPropertyNames ( O, kind ), https://tc39.es/ecma262/#sec-enumerableownpropertynames
  335. MarkedValueList Object::enumerable_own_property_names(PropertyKind kind) const
  336. {
  337. // NOTE: This has been flattened for readability, so some `else` branches in the
  338. // spec text have been replaced with `continue`s in the loop below.
  339. auto& vm = this->vm();
  340. auto& global_object = this->global_object();
  341. // 1. Assert: Type(O) is Object.
  342. // 2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
  343. auto own_keys = internal_own_property_keys();
  344. if (vm.exception())
  345. return MarkedValueList { heap() };
  346. // 3. Let properties be a new empty List.
  347. auto properties = MarkedValueList { heap() };
  348. // 4. For each element key of ownKeys, do
  349. for (auto& key : own_keys) {
  350. // a. If Type(key) is String, then
  351. if (!key.is_string())
  352. continue;
  353. auto property_name = PropertyName::from_value(global_object, key);
  354. // i. Let desc be ? O.[[GetOwnProperty]](key).
  355. auto descriptor = internal_get_own_property(property_name);
  356. if (vm.exception())
  357. return MarkedValueList { heap() };
  358. // ii. If desc is not undefined and desc.[[Enumerable]] is true, then
  359. if (descriptor.has_value() && *descriptor->enumerable) {
  360. // 1. If kind is key, append key to properties.
  361. if (kind == PropertyKind::Key) {
  362. properties.append(key);
  363. continue;
  364. }
  365. // 2. Else,
  366. // a. Let value be ? Get(O, key).
  367. auto value = get(property_name);
  368. if (vm.exception())
  369. return MarkedValueList { heap() };
  370. // b. If kind is value, append value to properties.
  371. if (kind == PropertyKind::Value) {
  372. properties.append(value);
  373. continue;
  374. }
  375. // c. Else,
  376. // i. Assert: kind is key+value.
  377. VERIFY(kind == PropertyKind::KeyAndValue);
  378. // ii. Let entry be ! CreateArrayFromList(« key, value »).
  379. auto entry = Array::create_from(global_object, { key, value });
  380. // iii. Append entry to properties.
  381. properties.append(entry);
  382. }
  383. }
  384. // 5. Return properties.
  385. return properties;
  386. }
  387. // 10.1 Ordinary Object Internal Methods and Internal Slots, https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
  388. // 10.1.1 [[GetPrototypeOf]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof
  389. Object* Object::internal_get_prototype_of() const
  390. {
  391. // 1. Return O.[[Prototype]].
  392. return const_cast<Object*>(prototype());
  393. }
  394. // 10.1.2 [[SetPrototypeOf]] ( V ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-setprototypeof-v
  395. bool Object::internal_set_prototype_of(Object* new_prototype)
  396. {
  397. // 1. Assert: Either Type(V) is Object or Type(V) is Null.
  398. // 2. Let current be O.[[Prototype]].
  399. // 3. If SameValue(V, current) is true, return true.
  400. if (prototype() == new_prototype)
  401. return true;
  402. // 4. Let extensible be O.[[Extensible]].
  403. // 5. If extensible is false, return false.
  404. if (!m_is_extensible)
  405. return false;
  406. // 6. Let p be V.
  407. auto* prototype = new_prototype;
  408. // 7. Let done be false.
  409. // 8. Repeat, while done is false,
  410. while (prototype) {
  411. // a. If p is null, set done to true.
  412. // b. Else if SameValue(p, O) is true, return false.
  413. if (prototype == this)
  414. return false;
  415. // c. Else,
  416. // i. If p.[[GetPrototypeOf]] is not the ordinary object internal method defined in 10.1.1, set done to true.
  417. // NOTE: This is a best-effort implementation; we don't have a good way of detecting whether certain virtual
  418. // Object methods have been overridden by a given object, but as ProxyObject is the only one doing that for
  419. // [[SetPrototypeOf]], this check does the trick.
  420. if (is<ProxyObject>(prototype))
  421. break;
  422. // ii. Else, set p to p.[[Prototype]].
  423. prototype = prototype->prototype();
  424. }
  425. // 9. Set O.[[Prototype]] to V.
  426. auto& shape = this->shape();
  427. if (shape.is_unique())
  428. shape.set_prototype_without_transition(new_prototype);
  429. else
  430. m_shape = shape.create_prototype_transition(new_prototype);
  431. // 10. Return true.
  432. return true;
  433. }
  434. // 10.1.3 [[IsExtensible]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-isextensible
  435. bool Object::internal_is_extensible() const
  436. {
  437. // 1. Return O.[[Extensible]].
  438. return m_is_extensible;
  439. }
  440. // 10.1.4 [[PreventExtensions]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-preventextensions
  441. bool Object::internal_prevent_extensions()
  442. {
  443. // 1. Set O.[[Extensible]] to false.
  444. m_is_extensible = false;
  445. // 2. Return true.
  446. return true;
  447. }
  448. // 10.1.5 [[GetOwnProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-getownproperty-p
  449. Optional<PropertyDescriptor> Object::internal_get_own_property(PropertyName const& property_name) const
  450. {
  451. // 1. Assert: IsPropertyKey(P) is true.
  452. VERIFY(property_name.is_valid());
  453. // 2. If O does not have an own property with key P, return undefined.
  454. if (!storage_has(property_name))
  455. return {};
  456. // 3. Let D be a newly created Property Descriptor with no fields.
  457. PropertyDescriptor descriptor;
  458. // 4. Let X be O's own property whose key is P.
  459. auto [value, attributes] = *storage_get(property_name);
  460. // 5. If X is a data property, then
  461. if (!value.is_accessor()) {
  462. // a. Set D.[[Value]] to the value of X's [[Value]] attribute.
  463. descriptor.value = value.value_or(js_undefined());
  464. // b. Set D.[[Writable]] to the value of X's [[Writable]] attribute.
  465. descriptor.writable = attributes.is_writable();
  466. }
  467. // 6. Else,
  468. else {
  469. // a. Assert: X is an accessor property.
  470. // b. Set D.[[Get]] to the value of X's [[Get]] attribute.
  471. descriptor.get = value.as_accessor().getter();
  472. // c. Set D.[[Set]] to the value of X's [[Set]] attribute.
  473. descriptor.set = value.as_accessor().setter();
  474. }
  475. // 7. Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute.
  476. descriptor.enumerable = attributes.is_enumerable();
  477. // 8. Set D.[[Configurable]] to the value of X's [[Configurable]] attribute.
  478. descriptor.configurable = attributes.is_configurable();
  479. // 9. Return D.
  480. return descriptor;
  481. }
  482. // 10.1.6 [[DefineOwnProperty]] ( P, Desc ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc
  483. bool Object::internal_define_own_property(PropertyName const& property_name, PropertyDescriptor const& property_descriptor)
  484. {
  485. VERIFY(property_name.is_valid());
  486. auto& vm = this->vm();
  487. // 1. Let current be ? O.[[GetOwnProperty]](P).
  488. auto current = internal_get_own_property(property_name);
  489. if (vm.exception())
  490. return {};
  491. // 2. Let extensible be ? IsExtensible(O).
  492. auto extensible = is_extensible();
  493. if (vm.exception())
  494. return {};
  495. // 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).
  496. return validate_and_apply_property_descriptor(this, property_name, extensible, property_descriptor, current);
  497. }
  498. // 10.1.7 [[HasProperty]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-hasproperty-p
  499. bool Object::internal_has_property(PropertyName const& property_name) const
  500. {
  501. auto& vm = this->vm();
  502. // 1. Assert: IsPropertyKey(P) is true.
  503. VERIFY(property_name.is_valid());
  504. // 2. Let hasOwn be ? O.[[GetOwnProperty]](P).
  505. auto has_own = internal_get_own_property(property_name);
  506. if (vm.exception())
  507. return {};
  508. // 3. If hasOwn is not undefined, return true.
  509. if (has_own.has_value())
  510. return true;
  511. // 4. Let parent be ? O.[[GetPrototypeOf]]().
  512. auto parent = internal_get_prototype_of();
  513. if (vm.exception())
  514. return {};
  515. // 5. If parent is not null, then
  516. if (parent) {
  517. // a. Return ? parent.[[HasProperty]](P).
  518. return parent->internal_has_property(property_name);
  519. }
  520. // 6. Return false.
  521. return false;
  522. }
  523. // 10.1.8 [[Get]] ( P, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver
  524. Value Object::internal_get(PropertyName const& property_name, Value receiver) const
  525. {
  526. VERIFY(!receiver.is_empty());
  527. auto& vm = this->vm();
  528. // 1. Assert: IsPropertyKey(P) is true.
  529. VERIFY(property_name.is_valid());
  530. // 2. Let desc be ? O.[[GetOwnProperty]](P).
  531. auto descriptor = internal_get_own_property(property_name);
  532. if (vm.exception())
  533. return {};
  534. // 3. If desc is undefined, then
  535. if (!descriptor.has_value()) {
  536. // a. Let parent be ? O.[[GetPrototypeOf]]().
  537. auto parent = internal_get_prototype_of();
  538. if (vm.exception())
  539. return {};
  540. // b. If parent is null, return undefined.
  541. if (!parent)
  542. return js_undefined();
  543. // c. Return ? parent.[[Get]](P, Receiver).
  544. return parent->internal_get(property_name, receiver);
  545. }
  546. // 4. If IsDataDescriptor(desc) is true, return desc.[[Value]].
  547. if (descriptor->is_data_descriptor())
  548. return *descriptor->value;
  549. // 5. Assert: IsAccessorDescriptor(desc) is true.
  550. VERIFY(descriptor->is_accessor_descriptor());
  551. // 6. Let getter be desc.[[Get]].
  552. auto* getter = *descriptor->get;
  553. // 7. If getter is undefined, return undefined.
  554. if (!getter)
  555. return js_undefined();
  556. // 8. Return ? Call(getter, Receiver).
  557. return vm.call(*getter, receiver);
  558. }
  559. static bool ordinary_set_with_own_descriptor(Object&, PropertyName const&, Value, Value, Optional<PropertyDescriptor>);
  560. // 10.1.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver
  561. bool Object::internal_set(PropertyName const& property_name, Value value, Value receiver)
  562. {
  563. VERIFY(!value.is_empty());
  564. VERIFY(!receiver.is_empty());
  565. auto& vm = this->vm();
  566. // 1. Assert: IsPropertyKey(P) is true.
  567. VERIFY(property_name.is_valid());
  568. // 2. Let ownDesc be ? O.[[GetOwnProperty]](P).
  569. auto own_descriptor = internal_get_own_property(property_name);
  570. if (vm.exception())
  571. return {};
  572. // 3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).
  573. return ordinary_set_with_own_descriptor(*this, property_name, value, receiver, own_descriptor);
  574. }
  575. // 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
  576. bool ordinary_set_with_own_descriptor(Object& object, PropertyName const& property_name, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor)
  577. {
  578. auto& vm = object.vm();
  579. // 1. Assert: IsPropertyKey(P) is true.
  580. VERIFY(property_name.is_valid());
  581. // 2. If ownDesc is undefined, then
  582. if (!own_descriptor.has_value()) {
  583. // a. Let parent be ? O.[[GetPrototypeOf]]().
  584. auto parent = object.internal_get_prototype_of();
  585. if (vm.exception())
  586. return {};
  587. // b. If parent is not null, then
  588. if (parent) {
  589. // i. Return ? parent.[[Set]](P, V, Receiver).
  590. return parent->internal_set(property_name, value, receiver);
  591. }
  592. // c. Else,
  593. else {
  594. // i. Set ownDesc to the PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
  595. own_descriptor = PropertyDescriptor {
  596. .value = js_undefined(),
  597. .writable = true,
  598. .enumerable = true,
  599. .configurable = true,
  600. };
  601. }
  602. }
  603. // 3. If IsDataDescriptor(ownDesc) is true, then
  604. if (own_descriptor->is_data_descriptor()) {
  605. // a. If ownDesc.[[Writable]] is false, return false.
  606. if (!*own_descriptor->writable)
  607. return false;
  608. // b. If Type(Receiver) is not Object, return false.
  609. if (!receiver.is_object())
  610. return false;
  611. // c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
  612. auto existing_descriptor = receiver.as_object().internal_get_own_property(property_name);
  613. if (vm.exception())
  614. return {};
  615. // d. If existingDescriptor is not undefined, then
  616. if (existing_descriptor.has_value()) {
  617. // i. If IsAccessorDescriptor(existingDescriptor) is true, return false.
  618. if (existing_descriptor->is_accessor_descriptor())
  619. return false;
  620. // ii. If existingDescriptor.[[Writable]] is false, return false.
  621. if (!*existing_descriptor->writable)
  622. return false;
  623. // iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }.
  624. auto value_descriptor = PropertyDescriptor { .value = value };
  625. // iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
  626. return receiver.as_object().internal_define_own_property(property_name, value_descriptor);
  627. }
  628. // e. Else,
  629. else {
  630. // i. Assert: Receiver does not currently have a property P.
  631. VERIFY(!receiver.as_object().storage_has(property_name));
  632. // ii. Return ? CreateDataProperty(Receiver, P, V).
  633. return receiver.as_object().create_data_property(property_name, value);
  634. }
  635. }
  636. // 4. Assert: IsAccessorDescriptor(ownDesc) is true.
  637. VERIFY(own_descriptor->is_accessor_descriptor());
  638. // 5. Let setter be ownDesc.[[Set]].
  639. auto* setter = *own_descriptor->set;
  640. // 6. If setter is undefined, return false.
  641. if (!setter)
  642. return false;
  643. // 7. Perform ? Call(setter, Receiver, « V »).
  644. (void)vm.call(*setter, receiver, value);
  645. // 8. Return true.
  646. return true;
  647. }
  648. // 10.1.10 [[Delete]] ( P ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-delete-p
  649. bool Object::internal_delete(PropertyName const& property_name)
  650. {
  651. auto& vm = this->vm();
  652. // 1. Assert: IsPropertyKey(P) is true.
  653. VERIFY(property_name.is_valid());
  654. // 2. Let desc be ? O.[[GetOwnProperty]](P).
  655. auto descriptor = internal_get_own_property(property_name);
  656. if (vm.exception())
  657. return {};
  658. // 3. If desc is undefined, return true.
  659. if (!descriptor.has_value())
  660. return true;
  661. // 4. If desc.[[Configurable]] is true, then
  662. if (*descriptor->configurable) {
  663. // a. Remove the own property with name P from O.
  664. storage_delete(property_name);
  665. // b. Return true.
  666. return true;
  667. }
  668. // 5. Return false.
  669. return false;
  670. }
  671. // 10.1.11 [[OwnPropertyKeys]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
  672. MarkedValueList Object::internal_own_property_keys() const
  673. {
  674. auto& vm = this->vm();
  675. // 1. Let keys be a new empty List.
  676. MarkedValueList keys { heap() };
  677. // 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do
  678. for (auto& entry : m_indexed_properties) {
  679. // a. Add P as the last element of keys.
  680. keys.append(js_string(vm, String::number(entry.index())));
  681. }
  682. // 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do
  683. for (auto& it : shape().property_table_ordered()) {
  684. if (it.key.is_string()) {
  685. // a. Add P as the last element of keys.
  686. keys.append(it.key.to_value(vm));
  687. }
  688. }
  689. // 4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do
  690. for (auto& it : shape().property_table_ordered()) {
  691. if (it.key.is_symbol()) {
  692. // a. Add P as the last element of keys.
  693. keys.append(it.key.to_value(vm));
  694. }
  695. }
  696. // 5. Return keys.
  697. return keys;
  698. }
  699. // 10.4.7.2 SetImmutablePrototype ( O, V ), https://tc39.es/ecma262/#sec-set-immutable-prototype
  700. bool Object::set_immutable_prototype(Object* prototype)
  701. {
  702. auto& vm = this->vm();
  703. // 1. Assert: Either Type(V) is Object or Type(V) is Null.
  704. // 2. Let current be ? O.[[GetPrototypeOf]]().
  705. auto* current = internal_get_prototype_of();
  706. if (vm.exception())
  707. return {};
  708. // 3. If SameValue(V, current) is true, return true.
  709. if (prototype == current)
  710. return true;
  711. // 4. Return false.
  712. return false;
  713. }
  714. Optional<ValueAndAttributes> Object::storage_get(PropertyName const& property_name) const
  715. {
  716. VERIFY(property_name.is_valid());
  717. Value value;
  718. PropertyAttributes attributes;
  719. if (property_name.is_number()) {
  720. auto value_and_attributes = m_indexed_properties.get(property_name.as_number());
  721. if (!value_and_attributes.has_value())
  722. return {};
  723. value = value_and_attributes->value;
  724. attributes = value_and_attributes->attributes;
  725. } else {
  726. auto metadata = shape().lookup(property_name.to_string_or_symbol());
  727. if (!metadata.has_value())
  728. return {};
  729. value = m_storage[metadata->offset];
  730. attributes = metadata->attributes;
  731. }
  732. return ValueAndAttributes { .value = value, .attributes = attributes };
  733. }
  734. bool Object::storage_has(PropertyName const& property_name) const
  735. {
  736. VERIFY(property_name.is_valid());
  737. if (property_name.is_number())
  738. return m_indexed_properties.has_index(property_name.as_number());
  739. return shape().lookup(property_name.to_string_or_symbol()).has_value();
  740. }
  741. void Object::storage_set(PropertyName const& property_name, ValueAndAttributes const& value_and_attributes)
  742. {
  743. VERIFY(property_name.is_valid());
  744. auto [value, attributes] = value_and_attributes;
  745. if (property_name.is_number()) {
  746. auto index = property_name.as_number();
  747. m_indexed_properties.put(index, value, attributes);
  748. return;
  749. }
  750. // NOTE: We disable transitions during initialize(), this makes building common runtime objects significantly faster.
  751. // Transitions are primarily interesting when scripts add properties to objects.
  752. if (!m_transitions_enabled && !m_shape->is_unique()) {
  753. m_shape->add_property_without_transition(property_name, attributes);
  754. m_storage.resize(m_shape->property_count());
  755. m_storage[m_shape->property_count() - 1] = value;
  756. return;
  757. }
  758. auto property_name_string_or_symbol = property_name.to_string_or_symbol();
  759. auto metadata = shape().lookup(property_name_string_or_symbol);
  760. if (!metadata.has_value()) {
  761. if (!m_shape->is_unique() && shape().property_count() > 100) {
  762. // If you add more than 100 properties to an object, let's stop doing
  763. // transitions to avoid filling up the heap with shapes.
  764. ensure_shape_is_unique();
  765. }
  766. if (m_shape->is_unique()) {
  767. m_shape->add_property_to_unique_shape(property_name_string_or_symbol, attributes);
  768. m_storage.resize(m_shape->property_count());
  769. } else if (m_transitions_enabled) {
  770. set_shape(*m_shape->create_put_transition(property_name_string_or_symbol, attributes));
  771. } else {
  772. m_shape->add_property_without_transition(property_name, attributes);
  773. m_storage.resize(m_shape->property_count());
  774. }
  775. metadata = shape().lookup(property_name_string_or_symbol);
  776. VERIFY(metadata.has_value());
  777. }
  778. if (attributes != metadata->attributes) {
  779. if (m_shape->is_unique()) {
  780. m_shape->reconfigure_property_in_unique_shape(property_name_string_or_symbol, attributes);
  781. } else {
  782. set_shape(*m_shape->create_configure_transition(property_name_string_or_symbol, attributes));
  783. }
  784. metadata = shape().lookup(property_name_string_or_symbol);
  785. VERIFY(metadata.has_value());
  786. }
  787. m_storage[metadata->offset] = value;
  788. }
  789. void Object::storage_delete(PropertyName const& property_name)
  790. {
  791. VERIFY(property_name.is_valid());
  792. VERIFY(storage_has(property_name));
  793. if (property_name.is_number())
  794. return m_indexed_properties.remove(property_name.as_number());
  795. auto metadata = shape().lookup(property_name.to_string_or_symbol());
  796. VERIFY(metadata.has_value());
  797. ensure_shape_is_unique();
  798. shape().remove_property_from_unique_shape(property_name.to_string_or_symbol(), metadata->offset);
  799. m_storage.remove(metadata->offset);
  800. }
  801. void Object::set_shape(Shape& new_shape)
  802. {
  803. m_storage.resize(new_shape.property_count());
  804. m_shape = &new_shape;
  805. }
  806. void Object::define_native_accessor(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attribute)
  807. {
  808. auto& vm = this->vm();
  809. String formatted_property_name;
  810. if (property_name.is_number()) {
  811. formatted_property_name = property_name.to_string();
  812. } else if (property_name.is_string()) {
  813. formatted_property_name = property_name.as_string();
  814. } else {
  815. formatted_property_name = String::formatted("[{}]", property_name.as_symbol()->description());
  816. }
  817. FunctionObject* getter_function = nullptr;
  818. if (getter) {
  819. auto name = String::formatted("get {}", formatted_property_name);
  820. getter_function = NativeFunction::create(global_object(), name, move(getter));
  821. getter_function->define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
  822. getter_function->define_direct_property(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable);
  823. }
  824. FunctionObject* setter_function = nullptr;
  825. if (setter) {
  826. auto name = String::formatted("set {}", formatted_property_name);
  827. setter_function = NativeFunction::create(global_object(), name, move(setter));
  828. setter_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
  829. setter_function->define_direct_property(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable);
  830. }
  831. return define_direct_accessor(property_name, getter_function, setter_function, attribute);
  832. }
  833. void Object::define_direct_accessor(PropertyName const& property_name, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes)
  834. {
  835. VERIFY(property_name.is_valid());
  836. auto existing_property = storage_get(property_name).value_or({}).value;
  837. auto* accessor = existing_property.is_accessor() ? &existing_property.as_accessor() : nullptr;
  838. if (!accessor) {
  839. accessor = Accessor::create(vm(), getter, setter);
  840. define_direct_property(property_name, accessor, attributes);
  841. } else {
  842. if (getter)
  843. accessor->set_getter(getter);
  844. if (setter)
  845. accessor->set_setter(setter);
  846. }
  847. }
  848. void Object::ensure_shape_is_unique()
  849. {
  850. if (shape().is_unique())
  851. return;
  852. m_shape = m_shape->create_unique_clone();
  853. }
  854. // Simple side-effect free property lookup, following the prototype chain. Non-standard.
  855. Value Object::get_without_side_effects(const PropertyName& property_name) const
  856. {
  857. auto* object = this;
  858. while (object) {
  859. auto value_and_attributes = object->storage_get(property_name);
  860. if (value_and_attributes.has_value())
  861. return value_and_attributes->value;
  862. object = object->prototype();
  863. }
  864. return {};
  865. }
  866. void Object::define_native_function(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)
  867. {
  868. auto& vm = this->vm();
  869. String function_name;
  870. if (property_name.is_string()) {
  871. function_name = property_name.as_string();
  872. } else {
  873. function_name = String::formatted("[{}]", property_name.as_symbol()->description());
  874. }
  875. auto* function = NativeFunction::create(global_object(), function_name, move(native_function));
  876. function->define_direct_property(vm.names.length, Value(length), Attribute::Configurable);
  877. function->define_direct_property(vm.names.name, js_string(vm.heap(), function_name), Attribute::Configurable);
  878. define_direct_property(property_name, function, attribute);
  879. }
  880. // 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties
  881. Object* Object::define_properties(Value properties)
  882. {
  883. auto& vm = this->vm();
  884. auto& global_object = this->global_object();
  885. // 1. Assert: Type(O) is Object.
  886. // 2. Let props be ? ToObject(Properties).
  887. auto* props = properties.to_object(global_object);
  888. if (vm.exception())
  889. return {};
  890. // 3. Let keys be ? props.[[OwnPropertyKeys]]().
  891. auto keys = props->internal_own_property_keys();
  892. if (vm.exception())
  893. return {};
  894. struct NameAndDescriptor {
  895. PropertyName name;
  896. PropertyDescriptor descriptor;
  897. };
  898. // 4. Let descriptors be a new empty List.
  899. Vector<NameAndDescriptor> descriptors;
  900. // 5. For each element nextKey of keys, do
  901. for (auto& next_key : keys) {
  902. auto property_name = PropertyName::from_value(global_object, next_key);
  903. // a. Let propDesc be ? props.[[GetOwnProperty]](nextKey).
  904. auto property_descriptor = props->internal_get_own_property(property_name);
  905. if (vm.exception())
  906. return {};
  907. // b. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
  908. if (property_descriptor.has_value() && *property_descriptor->enumerable) {
  909. // i. Let descObj be ? Get(props, nextKey).
  910. auto descriptor_object = props->get(property_name);
  911. if (vm.exception())
  912. return {};
  913. // ii. Let desc be ? ToPropertyDescriptor(descObj).
  914. auto descriptor = to_property_descriptor(global_object, descriptor_object);
  915. if (vm.exception())
  916. return {};
  917. // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
  918. descriptors.append({ property_name, descriptor });
  919. }
  920. }
  921. // 6. For each element pair of descriptors, do
  922. for (auto& [name, descriptor] : descriptors) {
  923. // a. Let P be the first element of pair.
  924. // b. Let desc be the second element of pair.
  925. // c. Perform ? DefinePropertyOrThrow(O, P, desc).
  926. define_property_or_throw(name, descriptor);
  927. if (vm.exception())
  928. return {};
  929. }
  930. // 7. Return O.
  931. return this;
  932. }
  933. void Object::visit_edges(Cell::Visitor& visitor)
  934. {
  935. Cell::visit_edges(visitor);
  936. visitor.visit(m_shape);
  937. for (auto& value : m_storage)
  938. visitor.visit(value);
  939. m_indexed_properties.for_each_value([&visitor](auto& value) {
  940. visitor.visit(value);
  941. });
  942. }
  943. // 7.1.1.1 OrdinaryToPrimitive ( O, hint ), https://tc39.es/ecma262/#sec-ordinarytoprimitive
  944. Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const
  945. {
  946. VERIFY(preferred_type == Value::PreferredType::String || preferred_type == Value::PreferredType::Number);
  947. auto& vm = this->vm();
  948. AK::Array<PropertyName, 2> method_names;
  949. if (preferred_type == Value::PreferredType::String)
  950. method_names = { vm.names.toString, vm.names.valueOf };
  951. else
  952. method_names = { vm.names.valueOf, vm.names.toString };
  953. for (auto& method_name : method_names) {
  954. auto method = get(method_name);
  955. if (vm.exception())
  956. return {};
  957. if (method.is_function()) {
  958. auto result = vm.call(method.as_function(), const_cast<Object*>(this));
  959. if (!result.is_object())
  960. return result;
  961. }
  962. }
  963. vm.throw_exception<TypeError>(global_object(), ErrorType::Convert, "object", preferred_type == Value::PreferredType::String ? "string" : "number");
  964. return {};
  965. }
  966. Value Object::invoke_internal(PropertyName const& property_name, Optional<MarkedValueList> arguments)
  967. {
  968. auto& vm = this->vm();
  969. auto property = get(property_name);
  970. if (vm.exception())
  971. return {};
  972. if (!property.is_function()) {
  973. vm.throw_exception<TypeError>(global_object(), ErrorType::NotAFunction, property.to_string_without_side_effects());
  974. return {};
  975. }
  976. return vm.call(property.as_function(), this, move(arguments));
  977. }
  978. }