Object.cpp 41 KB

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