Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1091 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); | 1091 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
| 1092 i::Handle<i::CallHandlerInfo> obj = | 1092 i::Handle<i::CallHandlerInfo> obj = |
| 1093 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1093 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
| 1094 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1094 SET_FIELD_WRAPPED(obj, set_callback, callback); |
| 1095 if (data.IsEmpty()) data = v8::Undefined(); | 1095 if (data.IsEmpty()) data = v8::Undefined(); |
| 1096 obj->set_data(*Utils::OpenHandle(*data)); | 1096 obj->set_data(*Utils::OpenHandle(*data)); |
| 1097 Utils::OpenHandle(this)->set_call_code(*obj); | 1097 Utils::OpenHandle(this)->set_call_code(*obj); |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 | 1100 |
| 1101 static i::Handle<i::AccessorInfo> MakeAccessorInfo( | 1101 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
| 1102 v8::Handle<String> name, | 1102 i::Handle<i::AccessorInfo> obj, |
| 1103 AccessorGetter getter, | 1103 v8::Handle<String> name, |
| 1104 AccessorSetter setter, | 1104 v8::AccessControl settings, |
| 1105 v8::Handle<Value> data, | 1105 v8::PropertyAttribute attributes, |
| 1106 v8::AccessControl settings, | 1106 v8::Handle<AccessorSignature> signature) { |
| 1107 v8::PropertyAttribute attributes, | |
| 1108 v8::Handle<AccessorSignature> signature) { | |
| 1109 i::Handle<i::ExecutableAccessorInfo> obj = | |
| 1110 FACTORY->NewExecutableAccessorInfo(); | |
| 1111 SET_FIELD_WRAPPED(obj, set_getter, getter); | |
| 1112 SET_FIELD_WRAPPED(obj, set_setter, setter); | |
| 1113 if (data.IsEmpty()) data = v8::Undefined(); | |
| 1114 obj->set_data(*Utils::OpenHandle(*data)); | |
| 1115 obj->set_name(*Utils::OpenHandle(*name)); | 1107 obj->set_name(*Utils::OpenHandle(*name)); |
| 1116 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); | 1108 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1117 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); | 1109 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1118 if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); | 1110 if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1119 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); | 1111 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
| 1120 if (!signature.IsEmpty()) { | 1112 if (!signature.IsEmpty()) { |
| 1121 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); | 1113 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); |
| 1122 } | 1114 } |
| 1123 return obj; | 1115 return obj; |
| 1124 } | 1116 } |
| 1125 | 1117 |
| 1126 | 1118 |
| 1127 void FunctionTemplate::AddInstancePropertyAccessor( | 1119 static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1128 v8::Handle<String> name, | 1120 v8::Handle<String> name, |
| 1129 AccessorGetter getter, | 1121 AccessorGetter getter, |
| 1130 AccessorSetter setter, | 1122 AccessorSetter setter, |
| 1131 v8::Handle<Value> data, | 1123 v8::Handle<Value> data, |
| 1132 v8::AccessControl settings, | 1124 v8::AccessControl settings, |
| 1133 v8::PropertyAttribute attributes, | 1125 v8::PropertyAttribute attributes, |
| 1134 v8::Handle<AccessorSignature> signature) { | 1126 v8::Handle<AccessorSignature> signature) { |
| 1135 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1127 i::Handle<i::ExecutableAccessorInfo> obj = |
| 1136 if (IsDeadCheck(isolate, | 1128 FACTORY->NewExecutableAccessorInfo(); |
|
Sven Panne
2013/02/19 08:41:16
Don't use FACTORY, get the Isolate via e.g. the na
| |
| 1137 "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { | 1129 SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1138 return; | 1130 SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1139 } | 1131 if (data.IsEmpty()) data = v8::Undefined(); |
| 1140 ENTER_V8(isolate); | 1132 obj->set_data(*Utils::OpenHandle(*data)); |
| 1141 i::HandleScope scope(isolate); | 1133 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
| 1142 | |
| 1143 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data, | |
| 1144 settings, attributes, | |
| 1145 signature); | |
| 1146 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); | |
| 1147 if (list->IsUndefined()) { | |
| 1148 list = NeanderArray().value(); | |
| 1149 Utils::OpenHandle(this)->set_property_accessors(*list); | |
| 1150 } | |
| 1151 NeanderArray array(list); | |
| 1152 array.add(obj); | |
| 1153 } | 1134 } |
| 1154 | 1135 |
| 1155 | 1136 |
| 1137 static i::Handle<i::AccessorInfo> MakeAccessorInfo( | |
| 1138 v8::Handle<String> name, | |
| 1139 const AccessorDescriptor* descriptor, | |
| 1140 v8::AccessControl settings, | |
| 1141 v8::PropertyAttribute attributes, | |
| 1142 v8::Handle<AccessorSignature> signature, | |
| 1143 i::Isolate* isolate) { | |
|
Sven Panne
2013/02/19 08:41:16
You don't need an explicit Isolate, just retrieve
| |
| 1144 i::Handle<i::DeclaredAccessorDescriptor> descriptor_internal = | |
| 1145 i::DeclaredAccessorDescriptor::Create(descriptor, isolate); | |
| 1146 if (descriptor_internal.is_null()) { | |
| 1147 return i::Handle<i::DeclaredAccessorInfo>(); | |
| 1148 } | |
| 1149 i::Handle<i::DeclaredAccessorInfo> obj = | |
| 1150 FACTORY->NewDeclaredAccessorInfo(); | |
|
Sven Panne
2013/02/19 08:41:16
Use isolate->factory() here.
| |
| 1151 obj->set_descriptor(*descriptor_internal); | |
| 1152 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); | |
| 1153 } | |
| 1154 | |
| 1155 | |
| 1156 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { | 1156 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
| 1157 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1157 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1158 if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") | 1158 if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") |
| 1159 || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) | 1159 || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
| 1160 return Local<ObjectTemplate>(); | 1160 return Local<ObjectTemplate>(); |
| 1161 ENTER_V8(isolate); | 1161 ENTER_V8(isolate); |
| 1162 if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { | 1162 if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { |
| 1163 Local<ObjectTemplate> templ = | 1163 Local<ObjectTemplate> templ = |
| 1164 ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); | 1164 ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); |
| 1165 Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); | 1165 Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1323 static void EnsureConstructor(ObjectTemplate* object_template) { | 1323 static void EnsureConstructor(ObjectTemplate* object_template) { |
| 1324 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { | 1324 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { |
| 1325 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 1325 Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1326 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); | 1326 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1327 constructor->set_instance_template(*Utils::OpenHandle(object_template)); | 1327 constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1328 Utils::OpenHandle(object_template)->set_constructor(*constructor); | 1328 Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1329 } | 1329 } |
| 1330 } | 1330 } |
| 1331 | 1331 |
| 1332 | 1332 |
| 1333 static inline void AddPropertyToFunctionTemplate( | |
| 1334 i::Handle<i::FunctionTemplateInfo> cons, | |
| 1335 i::Handle<i::AccessorInfo> obj) { | |
| 1336 i::Handle<i::Object> list(cons->property_accessors()); | |
| 1337 if (list->IsUndefined()) { | |
| 1338 list = NeanderArray().value(); | |
| 1339 cons->set_property_accessors(*list); | |
| 1340 } | |
| 1341 NeanderArray array(list); | |
| 1342 array.add(obj); | |
| 1343 } | |
| 1344 | |
| 1345 | |
| 1333 void ObjectTemplate::SetAccessor(v8::Handle<String> name, | 1346 void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1334 AccessorGetter getter, | 1347 AccessorGetter getter, |
| 1335 AccessorSetter setter, | 1348 AccessorSetter setter, |
| 1336 v8::Handle<Value> data, | 1349 v8::Handle<Value> data, |
| 1337 AccessControl settings, | 1350 AccessControl settings, |
| 1338 PropertyAttribute attribute, | 1351 PropertyAttribute attributes, |
| 1339 v8::Handle<AccessorSignature> signature) { | 1352 v8::Handle<AccessorSignature> signature) { |
| 1340 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1353 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1341 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; | 1354 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
| 1342 ENTER_V8(isolate); | 1355 ENTER_V8(isolate); |
| 1343 i::HandleScope scope(isolate); | 1356 i::HandleScope scope(isolate); |
| 1344 EnsureConstructor(this); | 1357 EnsureConstructor(this); |
| 1345 i::FunctionTemplateInfo* constructor = | 1358 i::FunctionTemplateInfo* constructor = |
| 1346 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); | 1359 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1347 i::Handle<i::FunctionTemplateInfo> cons(constructor); | 1360 i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1348 Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, | 1361 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data, |
| 1349 getter, | 1362 settings, attributes, |
| 1350 setter, | 1363 signature); |
| 1351 data, | 1364 AddPropertyToFunctionTemplate(cons, obj); |
| 1352 settings, | |
| 1353 attribute, | |
| 1354 signature); | |
| 1355 } | 1365 } |
| 1356 | 1366 |
| 1357 | 1367 |
| 1368 bool ObjectTemplate::SetAccessor(Handle<String> name, | |
| 1369 const AccessorDescriptor* descriptor, | |
| 1370 AccessControl settings, | |
| 1371 PropertyAttribute attributes, | |
| 1372 Handle<AccessorSignature> signature) { | |
| 1373 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 1374 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; | |
| 1375 ENTER_V8(isolate); | |
| 1376 i::HandleScope scope(isolate); | |
| 1377 EnsureConstructor(this); | |
| 1378 i::FunctionTemplateInfo* constructor = | |
| 1379 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); | |
| 1380 i::Handle<i::FunctionTemplateInfo> cons(constructor); | |
| 1381 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( | |
| 1382 name, descriptor, settings, attributes, signature, isolate); | |
| 1383 if (obj.is_null()) return false; | |
| 1384 AddPropertyToFunctionTemplate(cons, obj); | |
| 1385 return true; | |
| 1386 } | |
| 1387 | |
| 1388 | |
| 1358 void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, | 1389 void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1359 NamedPropertySetter setter, | 1390 NamedPropertySetter setter, |
| 1360 NamedPropertyQuery query, | 1391 NamedPropertyQuery query, |
| 1361 NamedPropertyDeleter remover, | 1392 NamedPropertyDeleter remover, |
| 1362 NamedPropertyEnumerator enumerator, | 1393 NamedPropertyEnumerator enumerator, |
| 1363 Handle<Value> data) { | 1394 Handle<Value> data) { |
| 1364 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1395 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1365 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { | 1396 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
| 1366 return; | 1397 return; |
| 1367 } | 1398 } |
| (...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3142 | 3173 |
| 3143 | 3174 |
| 3144 bool v8::Object::Has(uint32_t index) { | 3175 bool v8::Object::Has(uint32_t index) { |
| 3145 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3176 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3146 ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); | 3177 ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
| 3147 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3178 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3148 return self->HasElement(index); | 3179 return self->HasElement(index); |
| 3149 } | 3180 } |
| 3150 | 3181 |
| 3151 | 3182 |
| 3183 static inline bool SetAccessor(Object* obj, i::Handle<i::AccessorInfo> info) { | |
| 3184 if (info.is_null()) return false; | |
| 3185 bool fast = Utils::OpenHandle(obj)->HasFastProperties(); | |
| 3186 i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(obj), info); | |
| 3187 if (result.is_null() || result->IsUndefined()) return false; | |
| 3188 if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0); | |
| 3189 return true; | |
| 3190 } | |
| 3191 | |
| 3192 | |
| 3152 bool Object::SetAccessor(Handle<String> name, | 3193 bool Object::SetAccessor(Handle<String> name, |
| 3153 AccessorGetter getter, | 3194 AccessorGetter getter, |
| 3154 AccessorSetter setter, | 3195 AccessorSetter setter, |
| 3155 v8::Handle<Value> data, | 3196 v8::Handle<Value> data, |
| 3156 AccessControl settings, | 3197 AccessControl settings, |
| 3157 PropertyAttribute attributes) { | 3198 PropertyAttribute attributes) { |
| 3158 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3199 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3159 ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); | 3200 ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
| 3160 ENTER_V8(isolate); | 3201 ENTER_V8(isolate); |
| 3161 i::HandleScope scope(isolate); | 3202 i::HandleScope scope(isolate); |
| 3162 v8::Handle<AccessorSignature> signature; | 3203 v8::Handle<AccessorSignature> signature; |
| 3163 i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, getter, setter, data, | 3204 i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, getter, setter, data, |
| 3164 settings, attributes, | 3205 settings, attributes, |
| 3165 signature); | 3206 signature); |
| 3166 bool fast = Utils::OpenHandle(this)->HasFastProperties(); | 3207 return v8::SetAccessor(this, info); |
| 3167 i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); | |
| 3168 if (result.is_null() || result->IsUndefined()) return false; | |
| 3169 if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(this), 0); | |
| 3170 return true; | |
| 3171 } | 3208 } |
| 3172 | 3209 |
| 3173 | 3210 |
| 3211 bool Object::SetAccessor(Handle<String> name, | |
| 3212 const AccessorDescriptor* descriptor, | |
| 3213 AccessControl settings, | |
| 3214 PropertyAttribute attributes) { | |
| 3215 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 3216 ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); | |
| 3217 ENTER_V8(isolate); | |
| 3218 i::HandleScope scope(isolate); | |
| 3219 v8::Handle<AccessorSignature> signature; | |
| 3220 i::Handle<i::AccessorInfo> info = MakeAccessorInfo( | |
| 3221 name, descriptor, settings, attributes, signature, isolate); | |
| 3222 return v8::SetAccessor(this, info); | |
| 3223 } | |
| 3224 | |
| 3225 | |
| 3174 bool v8::Object::HasOwnProperty(Handle<String> key) { | 3226 bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3175 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3227 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3176 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", | 3228 ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3177 return false); | 3229 return false); |
| 3178 return Utils::OpenHandle(this)->HasLocalProperty( | 3230 return Utils::OpenHandle(this)->HasLocalProperty( |
| 3179 *Utils::OpenHandle(*key)); | 3231 *Utils::OpenHandle(*key)); |
| 3180 } | 3232 } |
| 3181 | 3233 |
| 3182 | 3234 |
| 3183 bool v8::Object::HasRealNamedProperty(Handle<String> key) { | 3235 bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
| (...skipping 3520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6704 | 6756 |
| 6705 v->VisitPointers(blocks_.first(), first_block_limit_); | 6757 v->VisitPointers(blocks_.first(), first_block_limit_); |
| 6706 | 6758 |
| 6707 for (int i = 1; i < blocks_.length(); i++) { | 6759 for (int i = 1; i < blocks_.length(); i++) { |
| 6708 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6760 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 6709 } | 6761 } |
| 6710 } | 6762 } |
| 6711 | 6763 |
| 6712 | 6764 |
| 6713 } } // namespace v8::internal | 6765 } } // namespace v8::internal |
| OLD | NEW |