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

Side by Side Diff: src/api.cc

Issue 1632603002: [api] Default native data property setter to replace the setter if the property is writable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 | « src/accessors.cc ('k') | src/api-natives.cc » ('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
11 #include <cmath> // For isnan. 11 #include <cmath> // For isnan.
12 #include <limits> 12 #include <limits>
13 #include <vector> 13 #include <vector>
14 #include "include/v8-debug.h" 14 #include "include/v8-debug.h"
15 #include "include/v8-experimental.h" 15 #include "include/v8-experimental.h"
16 #include "include/v8-profiler.h" 16 #include "include/v8-profiler.h"
17 #include "include/v8-testing.h" 17 #include "include/v8-testing.h"
18 #include "src/accessors.h"
18 #include "src/api-experimental.h" 19 #include "src/api-experimental.h"
19 #include "src/api-natives.h" 20 #include "src/api-natives.h"
20 #include "src/assert-scope.h" 21 #include "src/assert-scope.h"
21 #include "src/background-parsing-task.h" 22 #include "src/background-parsing-task.h"
22 #include "src/base/functional.h" 23 #include "src/base/functional.h"
23 #include "src/base/platform/platform.h" 24 #include "src/base/platform/platform.h"
24 #include "src/base/platform/time.h" 25 #include "src/base/platform/time.h"
25 #include "src/base/utils/random-number-generator.h" 26 #include "src/base/utils/random-number-generator.h"
26 #include "src/bootstrapper.h" 27 #include "src/bootstrapper.h"
27 #include "src/char-predicates-inl.h" 28 #include "src/char-predicates-inl.h"
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 obj->set_name(*Utils::OpenHandle(*name)); 1112 obj->set_name(*Utils::OpenHandle(*name));
1112 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); 1113 if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
1113 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); 1114 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
1114 obj->set_property_attributes(static_cast<i::PropertyAttributes>(attributes)); 1115 obj->set_property_attributes(static_cast<i::PropertyAttributes>(attributes));
1115 if (!signature.IsEmpty()) { 1116 if (!signature.IsEmpty()) {
1116 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); 1117 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
1117 } 1118 }
1118 return obj; 1119 return obj;
1119 } 1120 }
1120 1121
1121
1122 template <typename Getter, typename Setter> 1122 template <typename Getter, typename Setter>
1123 static i::Handle<i::AccessorInfo> MakeAccessorInfo( 1123 static i::Handle<i::AccessorInfo> MakeAccessorInfo(
1124 v8::Local<Name> name, Getter getter, Setter setter, v8::Local<Value> data, 1124 v8::Local<Name> name, Getter getter, Setter setter, v8::Local<Value> data,
1125 v8::AccessControl settings, v8::PropertyAttribute attributes, 1125 v8::AccessControl settings, v8::PropertyAttribute attributes,
1126 v8::Local<AccessorSignature> signature) { 1126 v8::Local<AccessorSignature> signature, bool is_special_data_property) {
1127 i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); 1127 i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
1128 i::Handle<i::AccessorInfo> obj = isolate->factory()->NewAccessorInfo(); 1128 i::Handle<i::AccessorInfo> obj = isolate->factory()->NewAccessorInfo();
1129 SET_FIELD_WRAPPED(obj, set_getter, getter); 1129 SET_FIELD_WRAPPED(obj, set_getter, getter);
1130 if (is_special_data_property && setter == nullptr) {
1131 setter = reinterpret_cast<Setter>(&i::Accessors::ReconfigureToDataProperty);
1132 }
1130 SET_FIELD_WRAPPED(obj, set_setter, setter); 1133 SET_FIELD_WRAPPED(obj, set_setter, setter);
1131 if (data.IsEmpty()) { 1134 if (data.IsEmpty()) {
1132 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1135 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1133 } 1136 }
1134 obj->set_data(*Utils::OpenHandle(*data)); 1137 obj->set_data(*Utils::OpenHandle(*data));
1138 obj->set_is_special_data_property(is_special_data_property);
1135 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); 1139 return SetAccessorInfoProperties(obj, name, settings, attributes, signature);
1136 } 1140 }
1137 1141
1138 1142
1139 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { 1143 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
1140 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true); 1144 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true);
1141 if (!Utils::ApiCheck(!handle.is_null(), 1145 if (!Utils::ApiCheck(!handle.is_null(),
1142 "v8::FunctionTemplate::InstanceTemplate()", 1146 "v8::FunctionTemplate::InstanceTemplate()",
1143 "Reading from empty handle")) { 1147 "Reading from empty handle")) {
1144 return Local<ObjectTemplate>(); 1148 return Local<ObjectTemplate>();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 1274
1271 1275
1272 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor 1276 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor
1273 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( 1277 static inline i::Handle<i::TemplateInfo> GetTemplateInfo(
1274 i::Isolate* isolate, 1278 i::Isolate* isolate,
1275 ObjectTemplate* object_template) { 1279 ObjectTemplate* object_template) {
1276 EnsureConstructor(isolate, object_template); 1280 EnsureConstructor(isolate, object_template);
1277 return Utils::OpenHandle(object_template); 1281 return Utils::OpenHandle(object_template);
1278 } 1282 }
1279 1283
1280 1284 template <typename Getter, typename Setter, typename Data, typename Template>
1281 template<typename Getter, typename Setter, typename Data, typename Template> 1285 static bool TemplateSetAccessor(Template* template_obj, v8::Local<Name> name,
1282 static bool TemplateSetAccessor( 1286 Getter getter, Setter setter, Data data,
1283 Template* template_obj, 1287 AccessControl settings,
1284 v8::Local<Name> name, 1288 PropertyAttribute attribute,
1285 Getter getter, 1289 v8::Local<AccessorSignature> signature,
1286 Setter setter, 1290 bool is_special_data_property) {
1287 Data data,
1288 AccessControl settings,
1289 PropertyAttribute attribute,
1290 v8::Local<AccessorSignature> signature) {
1291 auto isolate = Utils::OpenHandle(template_obj)->GetIsolate(); 1291 auto isolate = Utils::OpenHandle(template_obj)->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); 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 auto info = GetTemplateInfo(isolate, template_obj);
1298 i::ApiNatives::AddNativeDataProperty(isolate, info, obj); 1298 i::ApiNatives::AddNativeDataProperty(isolate, info, obj);
1299 return true; 1299 return true;
1300 } 1300 }
1301 1301
1302 1302
1303 void Template::SetNativeDataProperty(v8::Local<String> name, 1303 void Template::SetNativeDataProperty(v8::Local<String> name,
1304 AccessorGetterCallback getter, 1304 AccessorGetterCallback getter,
1305 AccessorSetterCallback setter, 1305 AccessorSetterCallback setter,
1306 v8::Local<Value> data, 1306 v8::Local<Value> data,
1307 PropertyAttribute attribute, 1307 PropertyAttribute attribute,
1308 v8::Local<AccessorSignature> signature, 1308 v8::Local<AccessorSignature> signature,
1309 AccessControl settings) { 1309 AccessControl settings) {
1310 TemplateSetAccessor( 1310 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
1311 this, name, getter, setter, data, settings, attribute, signature); 1311 signature, true);
1312 } 1312 }
1313 1313
1314 1314
1315 void Template::SetNativeDataProperty(v8::Local<Name> name, 1315 void Template::SetNativeDataProperty(v8::Local<Name> name,
1316 AccessorNameGetterCallback getter, 1316 AccessorNameGetterCallback getter,
1317 AccessorNameSetterCallback setter, 1317 AccessorNameSetterCallback setter,
1318 v8::Local<Value> data, 1318 v8::Local<Value> data,
1319 PropertyAttribute attribute, 1319 PropertyAttribute attribute,
1320 v8::Local<AccessorSignature> signature, 1320 v8::Local<AccessorSignature> signature,
1321 AccessControl settings) { 1321 AccessControl settings) {
1322 TemplateSetAccessor( 1322 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
1323 this, name, getter, setter, data, settings, attribute, signature); 1323 signature, true);
1324 } 1324 }
1325 1325
1326 1326
1327 void Template::SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic, 1327 void Template::SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
1328 PropertyAttribute attribute) { 1328 PropertyAttribute attribute) {
1329 auto templ = Utils::OpenHandle(this); 1329 auto templ = Utils::OpenHandle(this);
1330 i::Isolate* isolate = templ->GetIsolate(); 1330 i::Isolate* isolate = templ->GetIsolate();
1331 ENTER_V8(isolate); 1331 ENTER_V8(isolate);
1332 i::HandleScope scope(isolate); 1332 i::HandleScope scope(isolate);
1333 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), 1333 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
1334 intrinsic, 1334 intrinsic,
1335 static_cast<i::PropertyAttributes>(attribute)); 1335 static_cast<i::PropertyAttributes>(attribute));
1336 } 1336 }
1337 1337
1338 1338
1339 void ObjectTemplate::SetAccessor(v8::Local<String> name, 1339 void ObjectTemplate::SetAccessor(v8::Local<String> name,
1340 AccessorGetterCallback getter, 1340 AccessorGetterCallback getter,
1341 AccessorSetterCallback setter, 1341 AccessorSetterCallback setter,
1342 v8::Local<Value> data, AccessControl settings, 1342 v8::Local<Value> data, AccessControl settings,
1343 PropertyAttribute attribute, 1343 PropertyAttribute attribute,
1344 v8::Local<AccessorSignature> signature) { 1344 v8::Local<AccessorSignature> signature) {
1345 TemplateSetAccessor( 1345 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
1346 this, name, getter, setter, data, settings, attribute, signature); 1346 signature, i::FLAG_disable_old_api_accessors);
1347 } 1347 }
1348 1348
1349 1349
1350 void ObjectTemplate::SetAccessor(v8::Local<Name> name, 1350 void ObjectTemplate::SetAccessor(v8::Local<Name> name,
1351 AccessorNameGetterCallback getter, 1351 AccessorNameGetterCallback getter,
1352 AccessorNameSetterCallback setter, 1352 AccessorNameSetterCallback setter,
1353 v8::Local<Value> data, AccessControl settings, 1353 v8::Local<Value> data, AccessControl settings,
1354 PropertyAttribute attribute, 1354 PropertyAttribute attribute,
1355 v8::Local<AccessorSignature> signature) { 1355 v8::Local<AccessorSignature> signature) {
1356 TemplateSetAccessor( 1356 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
1357 this, name, getter, setter, data, settings, attribute, signature); 1357 signature, i::FLAG_disable_old_api_accessors);
1358 } 1358 }
1359 1359
1360 1360
1361 template <typename Getter, typename Setter, typename Query, typename Deleter, 1361 template <typename Getter, typename Setter, typename Query, typename Deleter,
1362 typename Enumerator> 1362 typename Enumerator>
1363 static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, 1363 static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ,
1364 Getter getter, Setter setter, 1364 Getter getter, Setter setter,
1365 Query query, Deleter remover, 1365 Query query, Deleter remover,
1366 Enumerator enumerator, 1366 Enumerator enumerator,
1367 Local<Value> data, 1367 Local<Value> data,
(...skipping 2544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 Local<Name> name, Getter getter, 3912 Local<Name> name, Getter getter,
3913 Setter setter, Data data, 3913 Setter setter, Data data,
3914 AccessControl settings, 3914 AccessControl settings,
3915 PropertyAttribute attributes) { 3915 PropertyAttribute attributes) {
3916 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::SetAccessor()", bool); 3916 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::SetAccessor()", bool);
3917 if (!Utils::OpenHandle(self)->IsJSObject()) return Just(false); 3917 if (!Utils::OpenHandle(self)->IsJSObject()) return Just(false);
3918 i::Handle<i::JSObject> obj = 3918 i::Handle<i::JSObject> obj =
3919 i::Handle<i::JSObject>::cast(Utils::OpenHandle(self)); 3919 i::Handle<i::JSObject>::cast(Utils::OpenHandle(self));
3920 v8::Local<AccessorSignature> signature; 3920 v8::Local<AccessorSignature> signature;
3921 auto info = MakeAccessorInfo(name, getter, setter, data, settings, attributes, 3921 auto info = MakeAccessorInfo(name, getter, setter, data, settings, attributes,
3922 signature); 3922 signature, i::FLAG_disable_old_api_accessors);
3923 if (info.is_null()) return Nothing<bool>(); 3923 if (info.is_null()) return Nothing<bool>();
3924 bool fast = obj->HasFastProperties(); 3924 bool fast = obj->HasFastProperties();
3925 i::Handle<i::Object> result; 3925 i::Handle<i::Object> result;
3926 has_pending_exception = 3926 has_pending_exception =
3927 !i::JSObject::SetAccessor(obj, info).ToHandle(&result); 3927 !i::JSObject::SetAccessor(obj, info).ToHandle(&result);
3928 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3928 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3929 if (result->IsUndefined()) return Nothing<bool>(); 3929 if (result->IsUndefined()) return Nothing<bool>();
3930 if (fast) { 3930 if (fast) {
3931 i::JSObject::MigrateSlowToFast(obj, 0, "APISetAccessor"); 3931 i::JSObject::MigrateSlowToFast(obj, 0, "APISetAccessor");
3932 } 3932 }
(...skipping 4617 matching lines...) Expand 10 before | Expand all | Expand 10 after
8550 Address callback_address = 8550 Address callback_address =
8551 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8551 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8552 VMState<EXTERNAL> state(isolate); 8552 VMState<EXTERNAL> state(isolate);
8553 ExternalCallbackScope call_scope(isolate, callback_address); 8553 ExternalCallbackScope call_scope(isolate, callback_address);
8554 callback(info); 8554 callback(info);
8555 } 8555 }
8556 8556
8557 8557
8558 } // namespace internal 8558 } // namespace internal
8559 } // namespace v8 8559 } // namespace v8
OLDNEW
« no previous file with comments | « src/accessors.cc ('k') | src/api-natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698