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 const char* name, Handle<Object> value) { | |
106 LookupIterator it(object, | |
107 isolate->factory()->NewStringFromAsciiChecked(name)); | |
108 Maybe<bool> result = JSObject::CreateDataProperty(&it, value); | |
109 CHECK(result.IsJust() && result.FromJust()); | |
110 } | |
111 | |
112 | |
113 // ES6 6.2.4.4 "FromPropertyDescriptor" | |
114 // We restrict ourselves to the case where the descriptor is either a complete | |
115 // accessor descriptor or a complete data descriptor, as is true for the result | |
116 // of JSReceiver::GetOwnPropertyDescriptor. | |
117 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { | |
118 DCHECK(PropertyDescriptor::IsAccessorDescriptor(this) != | |
119 PropertyDescriptor::IsDataDescriptor(this)); | |
120 Handle<JSObject> result = | |
121 isolate->factory()->NewJSObject(isolate->object_function()); | |
122 if (PropertyDescriptor::IsAccessorDescriptor(this)) { | |
123 DCHECK(has_get()); | |
124 CreateDataProperty(isolate, result, "get", get()); | |
Jakob Kummerow
2015/10/26 13:58:26
I'm a bit concerned about the speed of building ob
| |
125 DCHECK(has_set()); | |
126 CreateDataProperty(isolate, result, "set", set()); | |
127 } else { | |
128 DCHECK(has_value()); | |
129 CreateDataProperty(isolate, result, "value", value()); | |
130 DCHECK(has_writable()); | |
131 CreateDataProperty(isolate, result, "writable", | |
132 isolate->factory()->ToBoolean(writable())); | |
133 } | |
134 DCHECK(has_enumerable()); | |
135 CreateDataProperty(isolate, result, "enumerable", | |
136 isolate->factory()->ToBoolean(enumerable())); | |
137 DCHECK(has_configurable()); | |
138 CreateDataProperty(isolate, result, "configurable", | |
139 isolate->factory()->ToBoolean(configurable())); | |
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 |