Changeset 188361 in webkit
- Timestamp:
- Aug 12, 2015, 3:59:05 PM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r188357 r188361 1 2015-08-12 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [ES6] Implement Reflect.defineProperty 4 https://bugs.webkit.org/show_bug.cgi?id=147943 5 6 Reviewed by Saam Barati. 7 8 This patch implements Reflect.defineProperty. 9 The difference from the Object.defineProperty is, 10 11 1. Reflect.defineProperty does not perform ToObject operation onto the first argument. 12 2. Reflect.defineProperty does not throw a TypeError when the [[DefineOwnProperty]] operation fails. 13 3. Reflect.defineProperty returns the boolean value that represents whether [[DefineOwnProperty]] succeeded. 14 15 And this patch comments the links to the ES6 spec. 16 17 * builtins/ReflectObject.js: 18 * runtime/ObjectConstructor.cpp: 19 (JSC::toPropertyDescriptor): 20 * runtime/ObjectConstructor.h: 21 * runtime/ReflectObject.cpp: 22 (JSC::reflectObjectDefineProperty): 23 * tests/stress/reflect-define-property.js: Added. 24 (shouldBe): 25 (shouldThrow): 26 (.set getter): 27 (setter): 28 (.get testDescriptor): 29 (.set get var): 30 (.set testDescriptor): 31 (.set get testDescriptor): 32 (.set get shouldThrow): 33 (.get var): 34 1 35 2015-08-12 Filip Pizlo <fpizlo@apple.com> 2 36 -
trunk/Source/JavaScriptCore/builtins/ReflectObject.js
r188264 r188361 24 24 */ 25 25 26 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.apply 26 27 function apply(target, thisArgument, argumentsList) 27 28 { … … 37 38 } 38 39 40 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.deleteproperty 39 41 function deleteProperty(target, propertyKey) 40 42 { … … 48 50 } 49 51 52 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.has 50 53 function has(target, propertyKey) 51 54 { -
trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp
r188262 r188361 287 287 288 288 // ES5 8.10.5 ToPropertyDescriptor 289 staticbool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)289 bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc) 290 290 { 291 291 if (!in.isObject()) { -
trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h
r188262 r188361 94 94 JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*); 95 95 JSArray* ownPropertyKeys(ExecState*, JSObject*, PropertyNameMode, DontEnumPropertiesMode); 96 bool toPropertyDescriptor(ExecState*, JSValue, PropertyDescriptor&); 96 97 97 98 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/ReflectObject.cpp
r188264 r188361 35 35 namespace JSC { 36 36 37 static EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState*); 37 38 static EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState*); 38 39 static EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState*); … … 55 56 @begin reflectObjectTable 56 57 apply reflectObjectApply DontEnum|Function 3 58 defineProperty reflectObjectDefineProperty DontEnum|Function 3 57 59 deleteProperty reflectObjectDeleteProperty DontEnum|Function 2 58 60 enumerate reflectObjectEnumerate DontEnum|Function 1 … … 84 86 // ------------------------------ Functions -------------------------------- 85 87 88 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.defineproperty 89 EncodedJSValue JSC_HOST_CALL reflectObjectDefineProperty(ExecState* exec) 90 { 91 JSValue target = exec->argument(0); 92 if (!target.isObject()) 93 return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.defineProperty requires the first argument be an object"))); 94 auto propertyName = exec->argument(1).toPropertyKey(exec); 95 if (exec->hadException()) 96 return JSValue::encode(jsUndefined()); 97 98 PropertyDescriptor descriptor; 99 if (!toPropertyDescriptor(exec, exec->argument(2), descriptor)) 100 return JSValue::encode(jsUndefined()); 101 ASSERT((descriptor.attributes() & Accessor) || (!descriptor.isAccessorDescriptor())); 102 ASSERT(!exec->hadException()); 103 104 // Reflect.defineProperty should not throw an error when the defineOwnProperty operation fails. 105 bool shouldThrow = false; 106 JSObject* targetObject = asObject(target); 107 return JSValue::encode(jsBoolean(targetObject->methodTable(exec->vm())->defineOwnProperty(targetObject, exec, propertyName, descriptor, shouldThrow))); 108 } 109 110 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.enumerate 86 111 EncodedJSValue JSC_HOST_CALL reflectObjectEnumerate(ExecState* exec) 87 112 { … … 92 117 } 93 118 119 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.getprototypeof 94 120 EncodedJSValue JSC_HOST_CALL reflectObjectGetPrototypeOf(ExecState* exec) 95 121 { … … 100 126 } 101 127 128 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.isextensible 102 129 EncodedJSValue JSC_HOST_CALL reflectObjectIsExtensible(ExecState* exec) 103 130 { … … 108 135 } 109 136 137 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.ownkeys 110 138 EncodedJSValue JSC_HOST_CALL reflectObjectOwnKeys(ExecState* exec) 111 139 { … … 116 144 } 117 145 146 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.preventextensions 118 147 EncodedJSValue JSC_HOST_CALL reflectObjectPreventExtensions(ExecState* exec) 119 148 { … … 125 154 } 126 155 156 // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.setprototypeof 127 157 EncodedJSValue JSC_HOST_CALL reflectObjectSetPrototypeOf(ExecState* exec) 128 158 {
Note:
See TracChangeset
for help on using the changeset viewer.