| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/property-descriptor.h" | 5 #include "src/property-descriptor.h" |
| 6 | 6 |
| 7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
| 8 #include "src/factory.h" | 8 #include "src/factory.h" |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 #include "src/lookup.h" | 10 #include "src/lookup.h" |
| 11 #include "src/objects-inl.h" | 11 #include "src/objects-inl.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 namespace { |
| 17 |
| 16 // Helper function for ToPropertyDescriptor. Comments describe steps for | 18 // Helper function for ToPropertyDescriptor. Comments describe steps for |
| 17 // "enumerable", other properties are handled the same way. | 19 // "enumerable", other properties are handled the same way. |
| 18 // Returns false if an exception was thrown. | 20 // Returns false if an exception was thrown. |
| 19 bool GetPropertyIfPresent(Handle<Object> obj, Handle<String> name, | 21 bool GetPropertyIfPresent(Handle<Object> obj, Handle<String> name, |
| 20 Handle<Object>* value) { | 22 Handle<Object>* value) { |
| 21 LookupIterator it(obj, name); | 23 LookupIterator it(obj, name); |
| 22 // 4. Let hasEnumerable be HasProperty(Obj, "enumerable"). | 24 // 4. Let hasEnumerable be HasProperty(Obj, "enumerable"). |
| 23 Maybe<bool> has_property = JSReceiver::HasProperty(&it); | 25 Maybe<bool> has_property = JSReceiver::HasProperty(&it); |
| 24 // 5. ReturnIfAbrupt(hasEnumerable). | 26 // 5. ReturnIfAbrupt(hasEnumerable). |
| 25 if (has_property.IsNothing()) return false; | 27 if (has_property.IsNothing()) return false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 96 } |
| 95 if ((desc->has_get() || desc->has_set()) && | 97 if ((desc->has_get() || desc->has_set()) && |
| 96 (desc->has_value() || desc->has_writable())) { | 98 (desc->has_value() || desc->has_writable())) { |
| 97 // Bail out to slow path to throw an exception. | 99 // Bail out to slow path to throw an exception. |
| 98 return false; | 100 return false; |
| 99 } | 101 } |
| 100 return true; | 102 return true; |
| 101 } | 103 } |
| 102 | 104 |
| 103 | 105 |
| 104 static void CreateDataProperty(Isolate* isolate, Handle<JSObject> object, | 106 void CreateDataProperty(Isolate* isolate, Handle<JSObject> object, |
| 105 Handle<String> name, Handle<Object> value) { | 107 Handle<String> name, Handle<Object> value) { |
| 106 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 108 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 107 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); | 109 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); |
| 108 CHECK(result.IsJust() && result.FromJust()); | 110 CHECK(result.IsJust() && result.FromJust()); |
| 109 } | 111 } |
| 110 | 112 |
| 113 } // namespace |
| 114 |
| 111 | 115 |
| 112 // ES6 6.2.4.4 "FromPropertyDescriptor" | 116 // ES6 6.2.4.4 "FromPropertyDescriptor" |
| 113 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { | 117 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { |
| 114 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && | 118 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && |
| 115 PropertyDescriptor::IsDataDescriptor(this))); | 119 PropertyDescriptor::IsDataDescriptor(this))); |
| 116 Factory* factory = isolate->factory(); | 120 Factory* factory = isolate->factory(); |
| 121 if (IsRegularAccessorProperty()) { |
| 122 // Fast case for regular accessor properties. |
| 123 Handle<JSObject> result = factory->NewJSObjectFromMap( |
| 124 isolate->accessor_property_descriptor_map()); |
| 125 result->InObjectPropertyAtPut(JSAccessorPropertyDescriptor::kGetIndex, |
| 126 *get()); |
| 127 result->InObjectPropertyAtPut(JSAccessorPropertyDescriptor::kSetIndex, |
| 128 *set()); |
| 129 result->InObjectPropertyAtPut( |
| 130 JSAccessorPropertyDescriptor::kEnumerableIndex, |
| 131 isolate->heap()->ToBoolean(enumerable())); |
| 132 result->InObjectPropertyAtPut( |
| 133 JSAccessorPropertyDescriptor::kConfigurableIndex, |
| 134 isolate->heap()->ToBoolean(configurable())); |
| 135 return result; |
| 136 } |
| 137 if (IsRegularDataProperty()) { |
| 138 // Fast case for regular data properties. |
| 139 Handle<JSObject> result = |
| 140 factory->NewJSObjectFromMap(isolate->data_property_descriptor_map()); |
| 141 result->InObjectPropertyAtPut(JSDataPropertyDescriptor::kValueIndex, |
| 142 *value()); |
| 143 result->InObjectPropertyAtPut(JSDataPropertyDescriptor::kWritableIndex, |
| 144 isolate->heap()->ToBoolean(writable())); |
| 145 result->InObjectPropertyAtPut(JSDataPropertyDescriptor::kEnumerableIndex, |
| 146 isolate->heap()->ToBoolean(enumerable())); |
| 147 result->InObjectPropertyAtPut(JSDataPropertyDescriptor::kConfigurableIndex, |
| 148 isolate->heap()->ToBoolean(configurable())); |
| 149 return result; |
| 150 } |
| 117 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); | 151 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); |
| 118 if (has_value()) { | 152 if (has_value()) { |
| 119 CreateDataProperty(isolate, result, factory->value_string(), value()); | 153 CreateDataProperty(isolate, result, factory->value_string(), value()); |
| 120 } | 154 } |
| 121 if (has_writable()) { | 155 if (has_writable()) { |
| 122 CreateDataProperty(isolate, result, factory->writable_string(), | 156 CreateDataProperty(isolate, result, factory->writable_string(), |
| 123 factory->ToBoolean(writable())); | 157 factory->ToBoolean(writable())); |
| 124 } | 158 } |
| 125 if (has_get()) { | 159 if (has_get()) { |
| 126 CreateDataProperty(isolate, result, factory->get_string(), get()); | 160 CreateDataProperty(isolate, result, factory->get_string(), get()); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // Desc.[[Enumerable]] to like.[[Enumerable]]. | 325 // Desc.[[Enumerable]] to like.[[Enumerable]]. |
| 292 if (!desc->has_enumerable()) desc->set_enumerable(false); | 326 if (!desc->has_enumerable()) desc->set_enumerable(false); |
| 293 // 7. If Desc does not have a [[Configurable]] field, set | 327 // 7. If Desc does not have a [[Configurable]] field, set |
| 294 // Desc.[[Configurable]] to like.[[Configurable]]. | 328 // Desc.[[Configurable]] to like.[[Configurable]]. |
| 295 if (!desc->has_configurable()) desc->set_configurable(false); | 329 if (!desc->has_configurable()) desc->set_configurable(false); |
| 296 // 8. Return Desc. | 330 // 8. Return Desc. |
| 297 } | 331 } |
| 298 | 332 |
| 299 } // namespace internal | 333 } // namespace internal |
| 300 } // namespace v8 | 334 } // namespace v8 |
| OLD | NEW |