Object.cpp 41 KB

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