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" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } | 94 } |
95 if ((desc->has_get() || desc->has_set()) && | 95 if ((desc->has_get() || desc->has_set()) && |
96 (desc->has_value() || desc->has_writable())) { | 96 (desc->has_value() || desc->has_writable())) { |
97 // Bail out to slow path to throw an exception. | 97 // Bail out to slow path to throw an exception. |
98 return false; | 98 return false; |
99 } | 99 } |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 static void CreateDataProperty(Isolate* isolate, Handle<JSObject> object, | |
105 Handle<String> name, Handle<Object> value) { | |
106 LookupIterator it(object, name); | |
107 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); | |
108 CHECK(result.IsJust() && result.FromJust()); | |
109 } | |
110 | |
111 | |
112 // ES6 6.2.4.4 "FromPropertyDescriptor" | |
113 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { | |
114 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && | |
115 PropertyDescriptor::IsDataDescriptor(this))); | |
116 Factory* factory = isolate->factory(); | |
117 Handle<JSObject> result = | |
118 isolate->factory()->NewJSObject(isolate->object_function()); | |
119 if (has_value()) { | |
120 CreateDataProperty(isolate, result, factory->value_string(), value()); | |
121 } | |
122 if (has_writable()) { | |
123 CreateDataProperty(isolate, result, factory->writable_string(), | |
124 isolate->factory()->ToBoolean(writable())); | |
Jakob Kummerow
2015/10/30 08:55:19
nit: s/isolate->factory()/factory/, again twice be
neis
2015/10/30 09:42:58
Thanks.
| |
125 } | |
126 if (has_get()) { | |
127 CreateDataProperty(isolate, result, factory->get_string(), get()); | |
128 } | |
129 if (has_set()) { | |
130 CreateDataProperty(isolate, result, factory->set_string(), set()); | |
131 } | |
132 if (has_enumerable()) { | |
133 CreateDataProperty(isolate, result, factory->enumerable_string(), | |
134 isolate->factory()->ToBoolean(enumerable())); | |
135 } | |
136 if (has_configurable()) { | |
137 CreateDataProperty(isolate, result, factory->configurable_string(), | |
138 isolate->factory()->ToBoolean(configurable())); | |
139 } | |
140 return result; | |
141 } | |
142 | |
143 | |
104 // ES6 6.2.4.5 | 144 // ES6 6.2.4.5 |
105 // Returns false in case of exception. | 145 // Returns false in case of exception. |
106 // static | 146 // static |
107 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, | 147 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, |
108 Handle<Object> obj, | 148 Handle<Object> obj, |
109 PropertyDescriptor* desc) { | 149 PropertyDescriptor* desc) { |
110 // 1. ReturnIfAbrupt(Obj). | 150 // 1. ReturnIfAbrupt(Obj). |
111 // 2. If Type(Obj) is not Object, throw a TypeError exception. | 151 // 2. If Type(Obj) is not Object, throw a TypeError exception. |
112 if (!obj->IsSpecObject()) { | 152 if (!obj->IsSpecObject()) { |
113 isolate->Throw(*isolate->factory()->NewTypeError( | 153 isolate->Throw(*isolate->factory()->NewTypeError( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); | 260 *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); |
221 return false; | 261 return false; |
222 } | 262 } |
223 // 23. Return desc. | 263 // 23. Return desc. |
224 return true; | 264 return true; |
225 } | 265 } |
226 | 266 |
227 | 267 |
228 } // namespace internal | 268 } // namespace internal |
229 } // namespace v8 | 269 } // namespace v8 |
OLD | NEW |