PageRenderTime 30ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/qtwebkit/Source/JavaScriptCore/runtime/ObjectConstructor.cpp

https://gitlab.com/x33n/phantomjs
C++ | 518 lines | 386 code | 61 blank | 71 comment | 84 complexity | 0abaea0ba4475f0ee720dbf458054bde MD5 | raw file
  1. /*
  2. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2008 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. */
  20. #include "config.h"
  21. #include "ObjectConstructor.h"
  22. #include "ButterflyInlines.h"
  23. #include "CopiedSpaceInlines.h"
  24. #include "Error.h"
  25. #include "ExceptionHelpers.h"
  26. #include "JSFunction.h"
  27. #include "JSArray.h"
  28. #include "JSGlobalObject.h"
  29. #include "Lookup.h"
  30. #include "ObjectPrototype.h"
  31. #include "Operations.h"
  32. #include "PropertyDescriptor.h"
  33. #include "PropertyNameArray.h"
  34. namespace JSC {
  35. static EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*);
  36. static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*);
  37. static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*);
  38. static EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*);
  39. static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*);
  40. static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*);
  41. static EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState*);
  42. static EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState*);
  43. static EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState*);
  44. static EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState*);
  45. static EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState*);
  46. static EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState*);
  47. static EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState*);
  48. }
  49. #include "ObjectConstructor.lut.h"
  50. namespace JSC {
  51. ASSERT_HAS_TRIVIAL_DESTRUCTOR(ObjectConstructor);
  52. const ClassInfo ObjectConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::objectConstructorTable, CREATE_METHOD_TABLE(ObjectConstructor) };
  53. /* Source for ObjectConstructor.lut.h
  54. @begin objectConstructorTable
  55. getPrototypeOf objectConstructorGetPrototypeOf DontEnum|Function 1
  56. getOwnPropertyDescriptor objectConstructorGetOwnPropertyDescriptor DontEnum|Function 2
  57. getOwnPropertyNames objectConstructorGetOwnPropertyNames DontEnum|Function 1
  58. keys objectConstructorKeys DontEnum|Function 1
  59. defineProperty objectConstructorDefineProperty DontEnum|Function 3
  60. defineProperties objectConstructorDefineProperties DontEnum|Function 2
  61. create objectConstructorCreate DontEnum|Function 2
  62. seal objectConstructorSeal DontEnum|Function 1
  63. freeze objectConstructorFreeze DontEnum|Function 1
  64. preventExtensions objectConstructorPreventExtensions DontEnum|Function 1
  65. isSealed objectConstructorIsSealed DontEnum|Function 1
  66. isFrozen objectConstructorIsFrozen DontEnum|Function 1
  67. isExtensible objectConstructorIsExtensible DontEnum|Function 1
  68. @end
  69. */
  70. ObjectConstructor::ObjectConstructor(JSGlobalObject* globalObject, Structure* structure)
  71. : InternalFunction(globalObject, structure)
  72. {
  73. }
  74. void ObjectConstructor::finishCreation(ExecState* exec, ObjectPrototype* objectPrototype)
  75. {
  76. Base::finishCreation(exec->vm(), Identifier(exec, "Object").string());
  77. // ECMA 15.2.3.1
  78. putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, objectPrototype, DontEnum | DontDelete | ReadOnly);
  79. // no. of arguments for constructor
  80. putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
  81. }
  82. bool ObjectConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
  83. {
  84. return getStaticFunctionSlot<JSObject>(exec, ExecState::objectConstructorTable(exec), jsCast<ObjectConstructor*>(cell), propertyName, slot);
  85. }
  86. bool ObjectConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
  87. {
  88. return getStaticFunctionDescriptor<JSObject>(exec, ExecState::objectConstructorTable(exec), jsCast<ObjectConstructor*>(object), propertyName, descriptor);
  89. }
  90. static ALWAYS_INLINE JSObject* constructObject(ExecState* exec)
  91. {
  92. JSGlobalObject* globalObject = exec->callee()->globalObject();
  93. ArgList args(exec);
  94. JSValue arg = args.at(0);
  95. if (arg.isUndefinedOrNull())
  96. return constructEmptyObject(exec, globalObject->objectPrototype());
  97. return arg.toObject(exec, globalObject);
  98. }
  99. static EncodedJSValue JSC_HOST_CALL constructWithObjectConstructor(ExecState* exec)
  100. {
  101. return JSValue::encode(constructObject(exec));
  102. }
  103. ConstructType ObjectConstructor::getConstructData(JSCell*, ConstructData& constructData)
  104. {
  105. constructData.native.function = constructWithObjectConstructor;
  106. return ConstructTypeHost;
  107. }
  108. static EncodedJSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec)
  109. {
  110. return JSValue::encode(constructObject(exec));
  111. }
  112. CallType ObjectConstructor::getCallData(JSCell*, CallData& callData)
  113. {
  114. callData.native.function = callObjectConstructor;
  115. return CallTypeHost;
  116. }
  117. EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec)
  118. {
  119. if (!exec->argument(0).isObject())
  120. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested prototype of a value that is not an object.")));
  121. JSObject* object = asObject(exec->argument(0));
  122. if (!object->allowsAccessFrom(exec->trueCallerFrame()))
  123. return JSValue::encode(jsUndefined());
  124. return JSValue::encode(object->prototype());
  125. }
  126. EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec)
  127. {
  128. if (!exec->argument(0).isObject())
  129. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested property descriptor of a value that is not an object.")));
  130. String propertyName = exec->argument(1).toString(exec)->value(exec);
  131. if (exec->hadException())
  132. return JSValue::encode(jsNull());
  133. JSObject* object = asObject(exec->argument(0));
  134. PropertyDescriptor descriptor;
  135. if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, Identifier(exec, propertyName), descriptor))
  136. return JSValue::encode(jsUndefined());
  137. if (exec->hadException())
  138. return JSValue::encode(jsUndefined());
  139. JSObject* description = constructEmptyObject(exec);
  140. if (!descriptor.isAccessorDescriptor()) {
  141. description->putDirect(exec->vm(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
  142. description->putDirect(exec->vm(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0);
  143. } else {
  144. ASSERT(descriptor.getter());
  145. ASSERT(descriptor.setter());
  146. description->putDirect(exec->vm(), exec->propertyNames().get, descriptor.getter(), 0);
  147. description->putDirect(exec->vm(), exec->propertyNames().set, descriptor.setter(), 0);
  148. }
  149. description->putDirect(exec->vm(), exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0);
  150. description->putDirect(exec->vm(), exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0);
  151. return JSValue::encode(description);
  152. }
  153. // FIXME: Use the enumeration cache.
  154. EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState* exec)
  155. {
  156. if (!exec->argument(0).isObject())
  157. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested property names of a value that is not an object.")));
  158. PropertyNameArray properties(exec);
  159. asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, IncludeDontEnumProperties);
  160. JSArray* names = constructEmptyArray(exec, 0);
  161. size_t numProperties = properties.size();
  162. for (size_t i = 0; i < numProperties; i++)
  163. names->push(exec, jsOwnedString(exec, properties[i].string()));
  164. return JSValue::encode(names);
  165. }
  166. // FIXME: Use the enumeration cache.
  167. EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec)
  168. {
  169. if (!exec->argument(0).isObject())
  170. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Requested keys of a value that is not an object.")));
  171. PropertyNameArray properties(exec);
  172. asObject(exec->argument(0))->methodTable()->getOwnPropertyNames(asObject(exec->argument(0)), exec, properties, ExcludeDontEnumProperties);
  173. JSArray* keys = constructEmptyArray(exec, 0);
  174. size_t numProperties = properties.size();
  175. for (size_t i = 0; i < numProperties; i++)
  176. keys->push(exec, jsOwnedString(exec, properties[i].string()));
  177. return JSValue::encode(keys);
  178. }
  179. // ES5 8.10.5 ToPropertyDescriptor
  180. static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
  181. {
  182. if (!in.isObject()) {
  183. throwError(exec, createTypeError(exec, ASCIILiteral("Property description must be an object.")));
  184. return false;
  185. }
  186. JSObject* description = asObject(in);
  187. PropertySlot enumerableSlot(description);
  188. if (description->getPropertySlot(exec, exec->propertyNames().enumerable, enumerableSlot)) {
  189. desc.setEnumerable(enumerableSlot.getValue(exec, exec->propertyNames().enumerable).toBoolean(exec));
  190. if (exec->hadException())
  191. return false;
  192. }
  193. PropertySlot configurableSlot(description);
  194. if (description->getPropertySlot(exec, exec->propertyNames().configurable, configurableSlot)) {
  195. desc.setConfigurable(configurableSlot.getValue(exec, exec->propertyNames().configurable).toBoolean(exec));
  196. if (exec->hadException())
  197. return false;
  198. }
  199. JSValue value;
  200. PropertySlot valueSlot(description);
  201. if (description->getPropertySlot(exec, exec->propertyNames().value, valueSlot)) {
  202. desc.setValue(valueSlot.getValue(exec, exec->propertyNames().value));
  203. if (exec->hadException())
  204. return false;
  205. }
  206. PropertySlot writableSlot(description);
  207. if (description->getPropertySlot(exec, exec->propertyNames().writable, writableSlot)) {
  208. desc.setWritable(writableSlot.getValue(exec, exec->propertyNames().writable).toBoolean(exec));
  209. if (exec->hadException())
  210. return false;
  211. }
  212. PropertySlot getSlot(description);
  213. if (description->getPropertySlot(exec, exec->propertyNames().get, getSlot)) {
  214. JSValue get = getSlot.getValue(exec, exec->propertyNames().get);
  215. if (exec->hadException())
  216. return false;
  217. if (!get.isUndefined()) {
  218. CallData callData;
  219. if (getCallData(get, callData) == CallTypeNone) {
  220. throwError(exec, createTypeError(exec, ASCIILiteral("Getter must be a function.")));
  221. return false;
  222. }
  223. }
  224. desc.setGetter(get);
  225. }
  226. PropertySlot setSlot(description);
  227. if (description->getPropertySlot(exec, exec->propertyNames().set, setSlot)) {
  228. JSValue set = setSlot.getValue(exec, exec->propertyNames().set);
  229. if (exec->hadException())
  230. return false;
  231. if (!set.isUndefined()) {
  232. CallData callData;
  233. if (getCallData(set, callData) == CallTypeNone) {
  234. throwError(exec, createTypeError(exec, ASCIILiteral("Setter must be a function.")));
  235. return false;
  236. }
  237. }
  238. desc.setSetter(set);
  239. }
  240. if (!desc.isAccessorDescriptor())
  241. return true;
  242. if (desc.value()) {
  243. throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'value' present on property with getter or setter.")));
  244. return false;
  245. }
  246. if (desc.writablePresent()) {
  247. throwError(exec, createTypeError(exec, ASCIILiteral("Invalid property. 'writable' present on property with getter or setter.")));
  248. return false;
  249. }
  250. return true;
  251. }
  252. EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec)
  253. {
  254. if (!exec->argument(0).isObject())
  255. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects.")));
  256. JSObject* O = asObject(exec->argument(0));
  257. String propertyName = exec->argument(1).toString(exec)->value(exec);
  258. if (exec->hadException())
  259. return JSValue::encode(jsNull());
  260. PropertyDescriptor descriptor;
  261. if (!toPropertyDescriptor(exec, exec->argument(2), descriptor))
  262. return JSValue::encode(jsNull());
  263. ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor()));
  264. ASSERT(!exec->hadException());
  265. O->methodTable()->defineOwnProperty(O, exec, Identifier(exec, propertyName), descriptor, true);
  266. return JSValue::encode(O);
  267. }
  268. static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties)
  269. {
  270. PropertyNameArray propertyNames(exec);
  271. asObject(properties)->methodTable()->getOwnPropertyNames(asObject(properties), exec, propertyNames, ExcludeDontEnumProperties);
  272. size_t numProperties = propertyNames.size();
  273. Vector<PropertyDescriptor> descriptors;
  274. MarkedArgumentBuffer markBuffer;
  275. for (size_t i = 0; i < numProperties; i++) {
  276. PropertySlot slot;
  277. JSValue prop = properties->get(exec, propertyNames[i]);
  278. if (exec->hadException())
  279. return jsNull();
  280. PropertyDescriptor descriptor;
  281. if (!toPropertyDescriptor(exec, prop, descriptor))
  282. return jsNull();
  283. descriptors.append(descriptor);
  284. // Ensure we mark all the values that we're accumulating
  285. if (descriptor.isDataDescriptor() && descriptor.value())
  286. markBuffer.append(descriptor.value());
  287. if (descriptor.isAccessorDescriptor()) {
  288. if (descriptor.getter())
  289. markBuffer.append(descriptor.getter());
  290. if (descriptor.setter())
  291. markBuffer.append(descriptor.setter());
  292. }
  293. }
  294. for (size_t i = 0; i < numProperties; i++) {
  295. object->methodTable()->defineOwnProperty(object, exec, propertyNames[i], descriptors[i], true);
  296. if (exec->hadException())
  297. return jsNull();
  298. }
  299. return object;
  300. }
  301. EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState* exec)
  302. {
  303. if (!exec->argument(0).isObject())
  304. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Properties can only be defined on Objects.")));
  305. return JSValue::encode(defineProperties(exec, asObject(exec->argument(0)), exec->argument(1).toObject(exec)));
  306. }
  307. EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec)
  308. {
  309. if (!exec->argument(0).isObject() && !exec->argument(0).isNull())
  310. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object prototype may only be an Object or null.")));
  311. JSValue proto = exec->argument(0);
  312. JSObject* newObject = proto.isObject()
  313. ? constructEmptyObject(exec, asObject(proto))
  314. : constructEmptyObject(exec, exec->lexicalGlobalObject()->nullPrototypeObjectStructure());
  315. if (exec->argument(1).isUndefined())
  316. return JSValue::encode(newObject);
  317. if (!exec->argument(1).isObject())
  318. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Property descriptor list must be an Object.")));
  319. return JSValue::encode(defineProperties(exec, newObject, asObject(exec->argument(1))));
  320. }
  321. EncodedJSValue JSC_HOST_CALL objectConstructorSeal(ExecState* exec)
  322. {
  323. // 1. If Type(O) is not Object throw a TypeError exception.
  324. JSValue obj = exec->argument(0);
  325. if (!obj.isObject())
  326. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.seal can only be called on Objects.")));
  327. JSObject* object = asObject(obj);
  328. if (isJSFinalObject(object)) {
  329. object->seal(exec->vm());
  330. return JSValue::encode(obj);
  331. }
  332. // 2. For each named own property name P of O,
  333. PropertyNameArray properties(exec);
  334. object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties);
  335. PropertyNameArray::const_iterator end = properties.end();
  336. for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
  337. // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P.
  338. PropertyDescriptor desc;
  339. if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc))
  340. continue;
  341. // b. If desc.[[Configurable]] is true, set desc.[[Configurable]] to false.
  342. desc.setConfigurable(false);
  343. // c. Call the [[DefineOwnProperty]] internal method of O with P, desc, and true as arguments.
  344. object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true);
  345. if (exec->hadException())
  346. return JSValue::encode(obj);
  347. }
  348. // 3. Set the [[Extensible]] internal property of O to false.
  349. object->preventExtensions(exec->vm());
  350. // 4. Return O.
  351. return JSValue::encode(obj);
  352. }
  353. EncodedJSValue JSC_HOST_CALL objectConstructorFreeze(ExecState* exec)
  354. {
  355. // 1. If Type(O) is not Object throw a TypeError exception.
  356. JSValue obj = exec->argument(0);
  357. if (!obj.isObject())
  358. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.freeze can only be called on Objects.")));
  359. JSObject* object = asObject(obj);
  360. if (isJSFinalObject(object) && !hasIndexedProperties(object->structure()->indexingType())) {
  361. object->freeze(exec->vm());
  362. return JSValue::encode(obj);
  363. }
  364. // 2. For each named own property name P of O,
  365. PropertyNameArray properties(exec);
  366. object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties);
  367. PropertyNameArray::const_iterator end = properties.end();
  368. for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
  369. // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P.
  370. PropertyDescriptor desc;
  371. if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc))
  372. continue;
  373. // b. If IsDataDescriptor(desc) is true, then
  374. // i. If desc.[[Writable]] is true, set desc.[[Writable]] to false.
  375. if (desc.isDataDescriptor())
  376. desc.setWritable(false);
  377. // c. If desc.[[Configurable]] is true, set desc.[[Configurable]] to false.
  378. desc.setConfigurable(false);
  379. // d. Call the [[DefineOwnProperty]] internal method of O with P, desc, and true as arguments.
  380. object->methodTable()->defineOwnProperty(object, exec, *iter, desc, true);
  381. if (exec->hadException())
  382. return JSValue::encode(obj);
  383. }
  384. // 3. Set the [[Extensible]] internal property of O to false.
  385. object->preventExtensions(exec->vm());
  386. // 4. Return O.
  387. return JSValue::encode(obj);
  388. }
  389. EncodedJSValue JSC_HOST_CALL objectConstructorPreventExtensions(ExecState* exec)
  390. {
  391. JSValue obj = exec->argument(0);
  392. if (!obj.isObject())
  393. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.preventExtensions can only be called on Objects.")));
  394. asObject(obj)->preventExtensions(exec->vm());
  395. return JSValue::encode(obj);
  396. }
  397. EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState* exec)
  398. {
  399. // 1. If Type(O) is not Object throw a TypeError exception.
  400. JSValue obj = exec->argument(0);
  401. if (!obj.isObject())
  402. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isSealed can only be called on Objects.")));
  403. JSObject* object = asObject(obj);
  404. if (isJSFinalObject(object))
  405. return JSValue::encode(jsBoolean(object->isSealed(exec->vm())));
  406. // 2. For each named own property name P of O,
  407. PropertyNameArray properties(exec);
  408. object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties);
  409. PropertyNameArray::const_iterator end = properties.end();
  410. for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
  411. // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P.
  412. PropertyDescriptor desc;
  413. if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc))
  414. continue;
  415. // b. If desc.[[Configurable]] is true, then return false.
  416. if (desc.configurable())
  417. return JSValue::encode(jsBoolean(false));
  418. }
  419. // 3. If the [[Extensible]] internal property of O is false, then return true.
  420. // 4. Otherwise, return false.
  421. return JSValue::encode(jsBoolean(!object->isExtensible()));
  422. }
  423. EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState* exec)
  424. {
  425. // 1. If Type(O) is not Object throw a TypeError exception.
  426. JSValue obj = exec->argument(0);
  427. if (!obj.isObject())
  428. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isFrozen can only be called on Objects.")));
  429. JSObject* object = asObject(obj);
  430. if (isJSFinalObject(object))
  431. return JSValue::encode(jsBoolean(object->isFrozen(exec->vm())));
  432. // 2. For each named own property name P of O,
  433. PropertyNameArray properties(exec);
  434. object->methodTable()->getOwnPropertyNames(object, exec, properties, IncludeDontEnumProperties);
  435. PropertyNameArray::const_iterator end = properties.end();
  436. for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
  437. // a. Let desc be the result of calling the [[GetOwnProperty]] internal method of O with P.
  438. PropertyDescriptor desc;
  439. if (!object->methodTable()->getOwnPropertyDescriptor(object, exec, *iter, desc))
  440. continue;
  441. // b. If IsDataDescriptor(desc) is true then
  442. // i. If desc.[[Writable]] is true, return false. c. If desc.[[Configurable]] is true, then return false.
  443. if ((desc.isDataDescriptor() && desc.writable()) || desc.configurable())
  444. return JSValue::encode(jsBoolean(false));
  445. }
  446. // 3. If the [[Extensible]] internal property of O is false, then return true.
  447. // 4. Otherwise, return false.
  448. return JSValue::encode(jsBoolean(!object->isExtensible()));
  449. }
  450. EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState* exec)
  451. {
  452. JSValue obj = exec->argument(0);
  453. if (!obj.isObject())
  454. return throwVMError(exec, createTypeError(exec, ASCIILiteral("Object.isExtensible can only be called on Objects.")));
  455. return JSValue::encode(jsBoolean(asObject(obj)->isExtensible()));
  456. }
  457. } // namespace JSC