| 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 = factory->NewJSObject(isolate->object_function()); | 
|  | 118   if (has_value()) { | 
|  | 119     CreateDataProperty(isolate, result, factory->value_string(), value()); | 
|  | 120   } | 
|  | 121   if (has_writable()) { | 
|  | 122     CreateDataProperty(isolate, result, factory->writable_string(), | 
|  | 123                        factory->ToBoolean(writable())); | 
|  | 124   } | 
|  | 125   if (has_get()) { | 
|  | 126     CreateDataProperty(isolate, result, factory->get_string(), get()); | 
|  | 127   } | 
|  | 128   if (has_set()) { | 
|  | 129     CreateDataProperty(isolate, result, factory->set_string(), set()); | 
|  | 130   } | 
|  | 131   if (has_enumerable()) { | 
|  | 132     CreateDataProperty(isolate, result, factory->enumerable_string(), | 
|  | 133                        factory->ToBoolean(enumerable())); | 
|  | 134   } | 
|  | 135   if (has_configurable()) { | 
|  | 136     CreateDataProperty(isolate, result, factory->configurable_string(), | 
|  | 137                        factory->ToBoolean(configurable())); | 
|  | 138   } | 
|  | 139   return result; | 
|  | 140 } | 
|  | 141 | 
|  | 142 | 
| 104 // ES6 6.2.4.5 | 143 // ES6 6.2.4.5 | 
| 105 // Returns false in case of exception. | 144 // Returns false in case of exception. | 
| 106 // static | 145 // static | 
| 107 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, | 146 bool PropertyDescriptor::ToPropertyDescriptor(Isolate* isolate, | 
| 108                                               Handle<Object> obj, | 147                                               Handle<Object> obj, | 
| 109                                               PropertyDescriptor* desc) { | 148                                               PropertyDescriptor* desc) { | 
| 110   // 1. ReturnIfAbrupt(Obj). | 149   // 1. ReturnIfAbrupt(Obj). | 
| 111   // 2. If Type(Obj) is not Object, throw a TypeError exception. | 150   // 2. If Type(Obj) is not Object, throw a TypeError exception. | 
| 112   if (!obj->IsSpecObject()) { | 151   if (!obj->IsSpecObject()) { | 
| 113     isolate->Throw(*isolate->factory()->NewTypeError( | 152     isolate->Throw(*isolate->factory()->NewTypeError( | 
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 220         *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); | 259         *isolate->factory()->NewTypeError(MessageTemplate::kUnsupported)); | 
| 221     return false; | 260     return false; | 
| 222   } | 261   } | 
| 223   // 23. Return desc. | 262   // 23. Return desc. | 
| 224   return true; | 263   return true; | 
| 225 } | 264 } | 
| 226 | 265 | 
| 227 | 266 | 
| 228 }  // namespace internal | 267 }  // namespace internal | 
| 229 }  // namespace v8 | 268 }  // namespace v8 | 
| OLD | NEW | 
|---|