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 | |
18 // Helper function for ToPropertyDescriptor. Comments describe steps for | 16 // Helper function for ToPropertyDescriptor. Comments describe steps for |
19 // "enumerable", other properties are handled the same way. | 17 // "enumerable", other properties are handled the same way. |
20 // Returns false if an exception was thrown. | 18 // Returns false if an exception was thrown. |
21 bool GetPropertyIfPresent(Handle<Object> obj, Handle<String> name, | 19 bool GetPropertyIfPresent(Handle<Object> obj, Handle<String> name, |
22 Handle<Object>* value) { | 20 Handle<Object>* value) { |
23 LookupIterator it(obj, name); | 21 LookupIterator it(obj, name); |
24 // 4. Let hasEnumerable be HasProperty(Obj, "enumerable"). | 22 // 4. Let hasEnumerable be HasProperty(Obj, "enumerable"). |
25 Maybe<bool> has_property = JSReceiver::HasProperty(&it); | 23 Maybe<bool> has_property = JSReceiver::HasProperty(&it); |
26 // 5. ReturnIfAbrupt(hasEnumerable). | 24 // 5. ReturnIfAbrupt(hasEnumerable). |
27 if (has_property.IsNothing()) return false; | 25 if (has_property.IsNothing()) return false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 94 } |
97 if ((desc->has_get() || desc->has_set()) && | 95 if ((desc->has_get() || desc->has_set()) && |
98 (desc->has_value() || desc->has_writable())) { | 96 (desc->has_value() || desc->has_writable())) { |
99 // Bail out to slow path to throw an exception. | 97 // Bail out to slow path to throw an exception. |
100 return false; | 98 return false; |
101 } | 99 } |
102 return true; | 100 return true; |
103 } | 101 } |
104 | 102 |
105 | 103 |
106 void CreateDataProperty(Isolate* isolate, Handle<JSObject> object, | 104 static void CreateDataProperty(Isolate* isolate, Handle<JSObject> object, |
107 Handle<String> name, Handle<Object> value) { | 105 Handle<String> name, Handle<Object> value) { |
108 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 106 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
109 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); | 107 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); |
110 CHECK(result.IsJust() && result.FromJust()); | 108 CHECK(result.IsJust() && result.FromJust()); |
111 } | 109 } |
112 | 110 |
113 } // namespace | |
114 | |
115 | 111 |
116 // ES6 6.2.4.4 "FromPropertyDescriptor" | 112 // ES6 6.2.4.4 "FromPropertyDescriptor" |
117 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { | 113 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { |
118 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && | 114 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && |
119 PropertyDescriptor::IsDataDescriptor(this))); | 115 PropertyDescriptor::IsDataDescriptor(this))); |
120 Factory* factory = isolate->factory(); | 116 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 } | |
151 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); | 117 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); |
152 if (has_value()) { | 118 if (has_value()) { |
153 CreateDataProperty(isolate, result, factory->value_string(), value()); | 119 CreateDataProperty(isolate, result, factory->value_string(), value()); |
154 } | 120 } |
155 if (has_writable()) { | 121 if (has_writable()) { |
156 CreateDataProperty(isolate, result, factory->writable_string(), | 122 CreateDataProperty(isolate, result, factory->writable_string(), |
157 factory->ToBoolean(writable())); | 123 factory->ToBoolean(writable())); |
158 } | 124 } |
159 if (has_get()) { | 125 if (has_get()) { |
160 CreateDataProperty(isolate, result, factory->get_string(), get()); | 126 CreateDataProperty(isolate, result, factory->get_string(), get()); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // Desc.[[Enumerable]] to like.[[Enumerable]]. | 291 // Desc.[[Enumerable]] to like.[[Enumerable]]. |
326 if (!desc->has_enumerable()) desc->set_enumerable(false); | 292 if (!desc->has_enumerable()) desc->set_enumerable(false); |
327 // 7. If Desc does not have a [[Configurable]] field, set | 293 // 7. If Desc does not have a [[Configurable]] field, set |
328 // Desc.[[Configurable]] to like.[[Configurable]]. | 294 // Desc.[[Configurable]] to like.[[Configurable]]. |
329 if (!desc->has_configurable()) desc->set_configurable(false); | 295 if (!desc->has_configurable()) desc->set_configurable(false); |
330 // 8. Return Desc. | 296 // 8. Return Desc. |
331 } | 297 } |
332 | 298 |
333 } // namespace internal | 299 } // namespace internal |
334 } // namespace v8 | 300 } // namespace v8 |
OLD | NEW |