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 Handle<Object> PropertyDescriptor::ToObject(Isolate* isolate) { | |
115 DCHECK(!(PropertyDescriptor::IsAccessorDescriptor(this) && | |
116 PropertyDescriptor::IsDataDescriptor(this))); | |
117 Handle<JSObject> result = | |
118 isolate->factory()->NewJSObject(isolate->object_function()); | |
119 if (has_value()) CreateDataProperty(isolate, result, "value", value()); | |
Jakob Kummerow
2015/10/29 18:06:02
Instead of "value", please use isolate->factory()-
neis
2015/10/30 08:41:30
Done.
| |
120 if (has_writable()) { | |
121 CreateDataProperty(isolate, result, "writable", | |
122 isolate->factory()->ToBoolean(writable())); | |
123 } | |
124 if (has_get()) CreateDataProperty(isolate, result, "get", get()); | |
125 if (has_set()) CreateDataProperty(isolate, result, "set", set()); | |
126 if (has_enumerable()) { | |
127 CreateDataProperty(isolate, result, "enumerable", | |
128 isolate->factory()->ToBoolean(enumerable())); | |
129 } | |
130 if (has_configurable()) { | |
131 CreateDataProperty(isolate, result, "configurable", | |
132 isolate->factory()->ToBoolean(configurable())); | |
133 } | |
134 return result; | |
135 } | |
136 | |
137 | |
104 // ES6 6.2.4.5 | 138 // ES6 6.2.4.5 |
105 // Returns false in case of exception. | 139 // Returns false in case of exception. |
106 // static | 140 // static |
107 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, | 141 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, |
108 Handle<Object> obj, | 142 Handle<Object> obj, |
109 PropertyDescriptor* desc) { | 143 PropertyDescriptor* desc) { |
110 // 1. ReturnIfAbrupt(Obj). | 144 // 1. ReturnIfAbrupt(Obj). |
111 // 2. If Type(Obj) is not Object, throw a TypeError exception. | 145 // 2. If Type(Obj) is not Object, throw a TypeError exception. |
112 if (!obj->IsSpecObject()) { | 146 if (!obj->IsSpecObject()) { |
113 isolate->Throw(*isolate->factory()->NewTypeError( | 147 isolate->Throw(*isolate->factory()->NewTypeError( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); | 254 *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); |
221 return false; | 255 return false; |
222 } | 256 } |
223 // 23. Return desc. | 257 // 23. Return desc. |
224 return true; | 258 return true; |
225 } | 259 } |
226 | 260 |
227 | 261 |
228 } // namespace internal | 262 } // namespace internal |
229 } // namespace v8 | 263 } // namespace v8 |
OLD | NEW |