Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: src/api.cc

Issue 1660263003: Revert of [api] Make ObjectTemplate::SetNativeDataProperty() work even if the ObjectTemplate ... (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 } 962 }
963 963
964 964
965 // --- F u n c t i o n T e m p l a t e --- 965 // --- F u n c t i o n T e m p l a t e ---
966 static void InitializeFunctionTemplate( 966 static void InitializeFunctionTemplate(
967 i::Handle<i::FunctionTemplateInfo> info) { 967 i::Handle<i::FunctionTemplateInfo> info) {
968 InitializeTemplate(info, Consts::FUNCTION_TEMPLATE); 968 InitializeTemplate(info, Consts::FUNCTION_TEMPLATE);
969 info->set_flag(0); 969 info->set_flag(0);
970 } 970 }
971 971
972 static Local<ObjectTemplate> ObjectTemplateNew(
973 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
974 bool do_not_cache);
975 972
976 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { 973 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
977 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); 974 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
978 ENTER_V8(i_isolate); 975 ENTER_V8(i_isolate);
979 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), 976 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(),
980 i_isolate); 977 i_isolate);
981 if (result->IsUndefined()) { 978 if (result->IsUndefined()) {
982 // Do not cache prototype objects. 979 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(i_isolate);
983 result = Utils::OpenHandle( 980 result = Utils::OpenHandle(*ObjectTemplate::New(isolate));
984 *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true));
985 Utils::OpenHandle(this)->set_prototype_template(*result); 981 Utils::OpenHandle(this)->set_prototype_template(*result);
986 } 982 }
987 return ToApiHandle<ObjectTemplate>(result); 983 return ToApiHandle<ObjectTemplate>(result);
988 } 984 }
989 985
990 986
991 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info, 987 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info,
992 const char* func) { 988 const char* func) {
993 Utils::ApiCheck(!info->instantiated(), func, 989 Utils::ApiCheck(!info->instantiated(), func,
994 "FunctionTemplate already instantiated"); 990 "FunctionTemplate already instantiated");
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 Local<ObjectTemplate> ObjectTemplate::New( 1220 Local<ObjectTemplate> ObjectTemplate::New(
1225 Isolate* isolate, v8::Local<FunctionTemplate> constructor) { 1221 Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
1226 return New(reinterpret_cast<i::Isolate*>(isolate), constructor); 1222 return New(reinterpret_cast<i::Isolate*>(isolate), constructor);
1227 } 1223 }
1228 1224
1229 1225
1230 Local<ObjectTemplate> ObjectTemplate::New() { 1226 Local<ObjectTemplate> ObjectTemplate::New() {
1231 return New(i::Isolate::Current(), Local<FunctionTemplate>()); 1227 return New(i::Isolate::Current(), Local<FunctionTemplate>());
1232 } 1228 }
1233 1229
1234 static Local<ObjectTemplate> ObjectTemplateNew( 1230
1235 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, 1231 Local<ObjectTemplate> ObjectTemplate::New(
1236 bool do_not_cache) { 1232 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
1237 // Changes to the environment cannot be captured in the snapshot. Expect no 1233 // Changes to the environment cannot be captured in the snapshot. Expect no
1238 // object templates when the isolate is created for serialization. 1234 // object templates when the isolate is created for serialization.
1239 DCHECK(!isolate->serializer_enabled()); 1235 DCHECK(!isolate->serializer_enabled());
1240 LOG_API(isolate, "ObjectTemplate::New"); 1236 LOG_API(isolate, "ObjectTemplate::New");
1241 ENTER_V8(isolate); 1237 ENTER_V8(isolate);
1242 i::Handle<i::Struct> struct_obj = 1238 i::Handle<i::Struct> struct_obj =
1243 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); 1239 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE);
1244 i::Handle<i::ObjectTemplateInfo> obj = 1240 i::Handle<i::ObjectTemplateInfo> obj =
1245 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); 1241 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
1246 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); 1242 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
1247 int next_serial_number = 0;
1248 if (!do_not_cache) {
1249 next_serial_number = isolate->next_serial_number() + 1;
1250 isolate->set_next_serial_number(next_serial_number);
1251 }
1252 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
1253 if (!constructor.IsEmpty()) 1243 if (!constructor.IsEmpty())
1254 obj->set_constructor(*Utils::OpenHandle(*constructor)); 1244 obj->set_constructor(*Utils::OpenHandle(*constructor));
1255 obj->set_internal_field_count(i::Smi::FromInt(0)); 1245 obj->set_internal_field_count(i::Smi::FromInt(0));
1256 return Utils::ToLocal(obj); 1246 return Utils::ToLocal(obj);
1257 } 1247 }
1258 1248
1259 Local<ObjectTemplate> ObjectTemplate::New(
1260 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
1261 return ObjectTemplateNew(isolate, constructor, false);
1262 }
1263 1249
1264 // Ensure that the object template has a constructor. If no 1250 // Ensure that the object template has a constructor. If no
1265 // constructor is available we create one. 1251 // constructor is available we create one.
1266 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( 1252 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
1267 i::Isolate* isolate, 1253 i::Isolate* isolate,
1268 ObjectTemplate* object_template) { 1254 ObjectTemplate* object_template) {
1269 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); 1255 i::Object* obj = Utils::OpenHandle(object_template)->constructor();
1270 if (!obj ->IsUndefined()) { 1256 if (!obj ->IsUndefined()) {
1271 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); 1257 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj);
1272 return i::Handle<i::FunctionTemplateInfo>(info, isolate); 1258 return i::Handle<i::FunctionTemplateInfo>(info, isolate);
1273 } 1259 }
1274 Local<FunctionTemplate> templ = 1260 Local<FunctionTemplate> templ =
1275 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate)); 1261 FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
1276 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); 1262 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
1277 constructor->set_instance_template(*Utils::OpenHandle(object_template)); 1263 constructor->set_instance_template(*Utils::OpenHandle(object_template));
1278 Utils::OpenHandle(object_template)->set_constructor(*constructor); 1264 Utils::OpenHandle(object_template)->set_constructor(*constructor);
1279 return constructor; 1265 return constructor;
1280 } 1266 }
1281 1267
1282 1268
1269 static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
1270 i::Isolate* isolate,
1271 Template* template_obj) {
1272 return Utils::OpenHandle(template_obj);
1273 }
1274
1275
1276 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor
1277 static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
1278 i::Isolate* isolate,
1279 ObjectTemplate* object_template) {
1280 EnsureConstructor(isolate, object_template);
1281 return Utils::OpenHandle(object_template);
1282 }
1283
1283 template <typename Getter, typename Setter, typename Data, typename Template> 1284 template <typename Getter, typename Setter, typename Data, typename Template>
1284 static bool TemplateSetAccessor(Template* template_obj, v8::Local<Name> name, 1285 static bool TemplateSetAccessor(Template* template_obj, v8::Local<Name> name,
1285 Getter getter, Setter setter, Data data, 1286 Getter getter, Setter setter, Data data,
1286 AccessControl settings, 1287 AccessControl settings,
1287 PropertyAttribute attribute, 1288 PropertyAttribute attribute,
1288 v8::Local<AccessorSignature> signature, 1289 v8::Local<AccessorSignature> signature,
1289 bool is_special_data_property) { 1290 bool is_special_data_property) {
1290 auto info = Utils::OpenHandle(template_obj); 1291 auto isolate = Utils::OpenHandle(template_obj)->GetIsolate();
1291 auto isolate = info->GetIsolate();
1292 ENTER_V8(isolate); 1292 ENTER_V8(isolate);
1293 i::HandleScope scope(isolate); 1293 i::HandleScope scope(isolate);
1294 auto obj = MakeAccessorInfo(name, getter, setter, data, settings, attribute, 1294 auto obj = MakeAccessorInfo(name, getter, setter, data, settings, attribute,
1295 signature, is_special_data_property); 1295 signature, is_special_data_property);
1296 if (obj.is_null()) return false; 1296 if (obj.is_null()) return false;
1297 auto info = GetTemplateInfo(isolate, template_obj);
1297 i::ApiNatives::AddNativeDataProperty(isolate, info, obj); 1298 i::ApiNatives::AddNativeDataProperty(isolate, info, obj);
1298 return true; 1299 return true;
1299 } 1300 }
1300 1301
1301 1302
1302 void Template::SetNativeDataProperty(v8::Local<String> name, 1303 void Template::SetNativeDataProperty(v8::Local<String> name,
1303 AccessorGetterCallback getter, 1304 AccessorGetterCallback getter,
1304 AccessorSetterCallback setter, 1305 AccessorSetterCallback setter,
1305 v8::Local<Value> data, 1306 v8::Local<Value> data,
1306 PropertyAttribute attribute, 1307 PropertyAttribute attribute,
(...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after
3298 double Value::NumberValue() const { 3299 double Value::NumberValue() const {
3299 auto obj = Utils::OpenHandle(this); 3300 auto obj = Utils::OpenHandle(this);
3300 if (obj->IsNumber()) return obj->Number(); 3301 if (obj->IsNumber()) return obj->Number();
3301 return NumberValue(ContextFromHeapObject(obj)) 3302 return NumberValue(ContextFromHeapObject(obj))
3302 .FromMaybe(std::numeric_limits<double>::quiet_NaN()); 3303 .FromMaybe(std::numeric_limits<double>::quiet_NaN());
3303 } 3304 }
3304 3305
3305 3306
3306 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { 3307 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
3307 auto obj = Utils::OpenHandle(this); 3308 auto obj = Utils::OpenHandle(this);
3309 i::Handle<i::Object> num;
3308 if (obj->IsNumber()) { 3310 if (obj->IsNumber()) {
3309 return Just(NumberToInt64(*obj)); 3311 num = obj;
3312 } else {
3313 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t);
3314 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num);
3315 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t);
3310 } 3316 }
3311 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); 3317 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value())
3312 i::Handle<i::Object> num; 3318 : static_cast<int64_t>(num->Number()));
3313 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num);
3314 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t);
3315 return Just(NumberToInt64(*num));
3316 } 3319 }
3317 3320
3318 3321
3319 int64_t Value::IntegerValue() const { 3322 int64_t Value::IntegerValue() const {
3320 auto obj = Utils::OpenHandle(this); 3323 auto obj = Utils::OpenHandle(this);
3321 if (obj->IsNumber()) { 3324 if (obj->IsNumber()) {
3322 if (obj->IsSmi()) { 3325 if (obj->IsSmi()) {
3323 return i::Smi::cast(*obj)->value(); 3326 return i::Smi::cast(*obj)->value();
3324 } else { 3327 } else {
3325 return static_cast<int64_t>(obj->Number()); 3328 return static_cast<int64_t>(obj->Number());
(...skipping 5224 matching lines...) Expand 10 before | Expand all | Expand 10 after
8550 Address callback_address = 8553 Address callback_address =
8551 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8554 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8552 VMState<EXTERNAL> state(isolate); 8555 VMState<EXTERNAL> state(isolate);
8553 ExternalCallbackScope call_scope(isolate, callback_address); 8556 ExternalCallbackScope call_scope(isolate, callback_address);
8554 callback(info); 8557 callback(info);
8555 } 8558 }
8556 8559
8557 8560
8558 } // namespace internal 8561 } // namespace internal
8559 } // namespace v8 8562 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698