OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "test/cctest/test-api.h" | 7 #include "test/cctest/test-api.h" |
8 | 8 |
9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 void CheckThisNamedPropertyHandler( | 233 void CheckThisNamedPropertyHandler( |
234 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 234 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
235 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); | 235 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); |
236 ApiTestFuzzer::Fuzz(); | 236 ApiTestFuzzer::Fuzz(); |
237 CHECK(info.This() | 237 CHECK(info.This() |
238 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) | 238 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) |
239 .FromJust()); | 239 .FromJust()); |
240 } | 240 } |
241 | 241 |
242 void CheckThisIndexedPropertyDefiner( | |
243 uint32_t index, const v8::PropertyDescriptor& desc, | |
244 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
245 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyDefiner)); | |
246 ApiTestFuzzer::Fuzz(); | |
247 CHECK(info.This() | |
248 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) | |
249 .FromJust()); | |
250 } | |
251 | |
252 void CheckThisNamedPropertyDefiner( | |
253 Local<Name> property, const v8::PropertyDescriptor& desc, | |
254 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
255 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyDefiner)); | |
256 ApiTestFuzzer::Fuzz(); | |
257 CHECK(info.This() | |
258 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) | |
259 .FromJust()); | |
260 } | |
261 | |
262 void CheckThisIndexedPropertySetter( | 242 void CheckThisIndexedPropertySetter( |
263 uint32_t index, Local<Value> value, | 243 uint32_t index, Local<Value> value, |
264 const v8::PropertyCallbackInfo<v8::Value>& info) { | 244 const v8::PropertyCallbackInfo<v8::Value>& info) { |
265 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); | 245 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); |
266 ApiTestFuzzer::Fuzz(); | 246 ApiTestFuzzer::Fuzz(); |
267 CHECK(info.This() | 247 CHECK(info.This() |
268 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) | 248 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) |
269 .FromJust()); | 249 .FromJust()); |
270 } | 250 } |
271 | 251 |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 .ToLocalChecked() | 1096 .ToLocalChecked() |
1117 ->BooleanValue(env.local()) | 1097 ->BooleanValue(env.local()) |
1118 .FromJust()); | 1098 .FromJust()); |
1119 CHECK(v8_compile("delete obj.myProperty") | 1099 CHECK(v8_compile("delete obj.myProperty") |
1120 ->Run(env.local()) | 1100 ->Run(env.local()) |
1121 .ToLocalChecked() | 1101 .ToLocalChecked() |
1122 ->BooleanValue(env.local()) | 1102 ->BooleanValue(env.local()) |
1123 .FromJust()); | 1103 .FromJust()); |
1124 } | 1104 } |
1125 | 1105 |
1126 namespace { | |
1127 void NotInterceptingPropertyDefineCallback( | |
1128 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1129 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1130 // Do not intercept by not calling info.GetReturnValue().Set() | |
1131 } | |
1132 | |
1133 void InterceptingPropertyDefineCallback( | |
1134 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1135 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1136 // intercept the callback by setting a non-empty handle | |
1137 info.GetReturnValue().Set(name); | |
1138 } | |
1139 | |
1140 void CheckDescriptorInDefineCallback( | |
1141 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1142 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1143 CHECK(!desc.has_writable()); | |
1144 CHECK(!desc.has_value()); | |
1145 CHECK(!desc.has_enumerable()); | |
1146 CHECK(desc.has_configurable()); | |
1147 CHECK(!desc.configurable()); | |
1148 CHECK(desc.has_get()); | |
1149 CHECK(desc.get()->IsFunction()); | |
1150 CHECK(desc.has_set()); | |
1151 CHECK(desc.set()->IsUndefined()); | |
1152 // intercept the callback by setting a non-empty handle | |
1153 info.GetReturnValue().Set(name); | |
1154 } | |
1155 } // namespace | |
1156 | |
1157 THREADED_TEST(PropertyDefinerCallback) { | |
1158 v8::HandleScope scope(CcTest::isolate()); | |
1159 LocalContext env; | |
1160 | |
1161 { // Intercept defineProperty() | |
1162 v8::Local<v8::FunctionTemplate> templ = | |
1163 v8::FunctionTemplate::New(CcTest::isolate()); | |
1164 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1165 0, 0, 0, 0, 0, NotInterceptingPropertyDefineCallback)); | |
1166 env->Global() | |
1167 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1168 .ToLocalChecked() | |
1169 ->NewInstance(env.local()) | |
1170 .ToLocalChecked()) | |
1171 .FromJust(); | |
1172 const char* code = | |
1173 "obj.x = 17; " | |
1174 "Object.defineProperty(obj, 'x', {value: 42});" | |
1175 "obj.x;"; | |
1176 CHECK_EQ(42, v8_compile(code) | |
1177 ->Run(env.local()) | |
1178 .ToLocalChecked() | |
1179 ->Int32Value(env.local()) | |
1180 .FromJust()); | |
1181 } | |
1182 | |
1183 { // Intercept defineProperty() for correct accessor descriptor | |
1184 v8::Local<v8::FunctionTemplate> templ = | |
1185 v8::FunctionTemplate::New(CcTest::isolate()); | |
1186 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1187 0, 0, 0, 0, 0, CheckDescriptorInDefineCallback)); | |
1188 env->Global() | |
1189 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1190 .ToLocalChecked() | |
1191 ->NewInstance(env.local()) | |
1192 .ToLocalChecked()) | |
1193 .FromJust(); | |
1194 const char* code = | |
1195 "obj.x = 17; " | |
1196 "Object.defineProperty(obj, 'x', {" | |
1197 "get: function(){ return 42; }, " | |
1198 "set: undefined," | |
1199 "configurable: 0" | |
1200 "});" | |
1201 "obj.x;"; | |
1202 CHECK_EQ(17, v8_compile(code) | |
1203 ->Run(env.local()) | |
1204 .ToLocalChecked() | |
1205 ->Int32Value(env.local()) | |
1206 .FromJust()); | |
1207 } | |
1208 | |
1209 { // Do not intercept defineProperty() | |
1210 v8::Local<v8::FunctionTemplate> templ2 = | |
1211 v8::FunctionTemplate::New(CcTest::isolate()); | |
1212 templ2->InstanceTemplate()->SetHandler( | |
1213 v8::NamedPropertyHandlerConfiguration( | |
1214 0, 0, 0, 0, 0, InterceptingPropertyDefineCallback)); | |
1215 env->Global() | |
1216 ->Set(env.local(), v8_str("obj"), templ2->GetFunction(env.local()) | |
1217 .ToLocalChecked() | |
1218 ->NewInstance(env.local()) | |
1219 .ToLocalChecked()) | |
1220 .FromJust(); | |
1221 | |
1222 const char* code = | |
1223 "obj.x = 17; " | |
1224 "Object.defineProperty(obj, 'x', {value: 42});" | |
1225 "obj.x;"; | |
1226 CHECK_EQ(17, v8_compile(code) | |
1227 ->Run(env.local()) | |
1228 .ToLocalChecked() | |
1229 ->Int32Value(env.local()) | |
1230 .FromJust()); | |
1231 } | |
1232 } | |
1233 | |
1234 namespace { | |
1235 void NotInterceptingPropertyDefineCallbackIndexed( | |
1236 uint32_t index, const v8::PropertyDescriptor& desc, | |
1237 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1238 // Do not intercept by not calling info.GetReturnValue().Set() | |
1239 } | |
1240 | |
1241 void InterceptingPropertyDefineCallbackIndexed( | |
1242 uint32_t index, const v8::PropertyDescriptor& desc, | |
1243 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1244 // intercept the callback by setting a non-empty handle | |
1245 info.GetReturnValue().Set(index); | |
1246 } | |
1247 | |
1248 void CheckDescriptorInDefineCallbackIndexed( | |
1249 uint32_t index, const v8::PropertyDescriptor& desc, | |
1250 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1251 CHECK(!desc.has_writable()); | |
1252 CHECK(!desc.has_value()); | |
1253 CHECK(desc.has_enumerable()); | |
1254 CHECK(desc.enumerable()); | |
1255 CHECK(!desc.has_configurable()); | |
1256 CHECK(desc.has_get()); | |
1257 CHECK(desc.get()->IsFunction()); | |
1258 CHECK(desc.has_set()); | |
1259 CHECK(desc.set()->IsUndefined()); | |
1260 // intercept the callback by setting a non-empty handle | |
1261 info.GetReturnValue().Set(index); | |
1262 } | |
1263 } // namespace | |
1264 | |
1265 THREADED_TEST(PropertyDefinerCallbackIndexed) { | |
1266 v8::HandleScope scope(CcTest::isolate()); | |
1267 LocalContext env; | |
1268 | |
1269 { // Intercept defineProperty() | |
1270 v8::Local<v8::FunctionTemplate> templ = | |
1271 v8::FunctionTemplate::New(CcTest::isolate()); | |
1272 templ->InstanceTemplate()->SetHandler( | |
1273 v8::IndexedPropertyHandlerConfiguration( | |
1274 0, 0, 0, 0, 0, NotInterceptingPropertyDefineCallbackIndexed)); | |
1275 env->Global() | |
1276 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1277 .ToLocalChecked() | |
1278 ->NewInstance(env.local()) | |
1279 .ToLocalChecked()) | |
1280 .FromJust(); | |
1281 const char* code = | |
1282 "obj[2] = 17; " | |
1283 "Object.defineProperty(obj, 2, {value: 42});" | |
1284 "obj[2];"; | |
1285 CHECK_EQ(42, v8_compile(code) | |
1286 ->Run(env.local()) | |
1287 .ToLocalChecked() | |
1288 ->Int32Value(env.local()) | |
1289 .FromJust()); | |
1290 } | |
1291 | |
1292 { // Intercept defineProperty() for correct accessor descriptor | |
1293 v8::Local<v8::FunctionTemplate> templ = | |
1294 v8::FunctionTemplate::New(CcTest::isolate()); | |
1295 templ->InstanceTemplate()->SetHandler( | |
1296 v8::IndexedPropertyHandlerConfiguration( | |
1297 0, 0, 0, 0, 0, CheckDescriptorInDefineCallbackIndexed)); | |
1298 env->Global() | |
1299 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1300 .ToLocalChecked() | |
1301 ->NewInstance(env.local()) | |
1302 .ToLocalChecked()) | |
1303 .FromJust(); | |
1304 const char* code = | |
1305 "obj[2] = 17; " | |
1306 "Object.defineProperty(obj, 2, {" | |
1307 "get: function(){ return 42; }, " | |
1308 "set: undefined," | |
1309 "enumerable: true" | |
1310 "});" | |
1311 "obj[2];"; | |
1312 CHECK_EQ(17, v8_compile(code) | |
1313 ->Run(env.local()) | |
1314 .ToLocalChecked() | |
1315 ->Int32Value(env.local()) | |
1316 .FromJust()); | |
1317 } | |
1318 | |
1319 { // Do not intercept defineProperty() | |
1320 v8::Local<v8::FunctionTemplate> templ2 = | |
1321 v8::FunctionTemplate::New(CcTest::isolate()); | |
1322 templ2->InstanceTemplate()->SetHandler( | |
1323 v8::IndexedPropertyHandlerConfiguration( | |
1324 0, 0, 0, 0, 0, InterceptingPropertyDefineCallbackIndexed)); | |
1325 env->Global() | |
1326 ->Set(env.local(), v8_str("obj"), templ2->GetFunction(env.local()) | |
1327 .ToLocalChecked() | |
1328 ->NewInstance(env.local()) | |
1329 .ToLocalChecked()) | |
1330 .FromJust(); | |
1331 | |
1332 const char* code = | |
1333 "obj[2] = 17; " | |
1334 "Object.defineProperty(obj, 2, {value: 42});" | |
1335 "obj[2];"; | |
1336 CHECK_EQ(17, v8_compile(code) | |
1337 ->Run(env.local()) | |
1338 .ToLocalChecked() | |
1339 ->Int32Value(env.local()) | |
1340 .FromJust()); | |
1341 } | |
1342 } | |
1343 | |
1344 // Test that freeze() is intercepted. | |
1345 THREADED_TEST(PropertyDefinerCallbackForFreeze) { | |
1346 v8::HandleScope scope(CcTest::isolate()); | |
1347 LocalContext env; | |
1348 v8::Local<v8::FunctionTemplate> templ = | |
1349 v8::FunctionTemplate::New(CcTest::isolate()); | |
1350 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1351 0, 0, 0, 0, 0, InterceptingPropertyDefineCallback)); | |
1352 env->Global() | |
1353 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1354 .ToLocalChecked() | |
1355 ->NewInstance(env.local()) | |
1356 .ToLocalChecked()) | |
1357 .FromJust(); | |
1358 const char* code = | |
1359 "obj.x = 17; " | |
1360 "Object.freeze(obj.x); " | |
1361 "Object.isFrozen(obj.x);"; | |
1362 | |
1363 CHECK(v8_compile(code) | |
1364 ->Run(env.local()) | |
1365 .ToLocalChecked() | |
1366 ->BooleanValue(env.local()) | |
1367 .FromJust()); | |
1368 } | |
1369 | |
1370 // Check that the descriptor passed to the callback is enumerable. | |
1371 namespace { | |
1372 void CheckEnumerablePropertyDefineCallback( | |
1373 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1374 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1375 CHECK(desc.has_value()); | |
1376 CHECK_EQ(42, desc.value() | |
1377 ->Int32Value(info.GetIsolate()->GetCurrentContext()) | |
1378 .FromJust()); | |
1379 CHECK(desc.has_enumerable()); | |
1380 CHECK(desc.enumerable()); | |
1381 CHECK(!desc.has_writable()); | |
1382 | |
1383 // intercept the callback by setting a non-empty handle | |
1384 info.GetReturnValue().Set(name); | |
1385 } | |
1386 } // namespace | |
1387 THREADED_TEST(PropertyDefinerCallbackEnumerable) { | |
1388 v8::HandleScope scope(CcTest::isolate()); | |
1389 LocalContext env; | |
1390 v8::Local<v8::FunctionTemplate> templ = | |
1391 v8::FunctionTemplate::New(CcTest::isolate()); | |
1392 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1393 0, 0, 0, 0, 0, CheckEnumerablePropertyDefineCallback)); | |
1394 env->Global() | |
1395 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1396 .ToLocalChecked() | |
1397 ->NewInstance(env.local()) | |
1398 .ToLocalChecked()) | |
1399 .FromJust(); | |
1400 const char* code = | |
1401 "obj.x = 17; " | |
1402 "Object.defineProperty(obj, 'x', {value: 42, enumerable: true});" | |
1403 "obj.x;"; | |
1404 CHECK_EQ(17, v8_compile(code) | |
1405 ->Run(env.local()) | |
1406 .ToLocalChecked() | |
1407 ->Int32Value(env.local()) | |
1408 .FromJust()); | |
1409 } | |
1410 | |
1411 // Check that the descriptor passed to the callback is configurable. | |
1412 namespace { | |
1413 void CheckConfigurablePropertyDefineCallback( | |
1414 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1415 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1416 CHECK(desc.has_value()); | |
1417 CHECK_EQ(42, desc.value() | |
1418 ->Int32Value(info.GetIsolate()->GetCurrentContext()) | |
1419 .FromJust()); | |
1420 CHECK(desc.has_configurable()); | |
1421 CHECK(desc.configurable()); | |
1422 | |
1423 // intercept the callback by setting a non-empty handle | |
1424 info.GetReturnValue().Set(name); | |
1425 } | |
1426 } // namespace | |
1427 THREADED_TEST(PropertyDefinerCallbackConfigurable) { | |
1428 v8::HandleScope scope(CcTest::isolate()); | |
1429 LocalContext env; | |
1430 v8::Local<v8::FunctionTemplate> templ = | |
1431 v8::FunctionTemplate::New(CcTest::isolate()); | |
1432 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1433 0, 0, 0, 0, 0, CheckConfigurablePropertyDefineCallback)); | |
1434 env->Global() | |
1435 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1436 .ToLocalChecked() | |
1437 ->NewInstance(env.local()) | |
1438 .ToLocalChecked()) | |
1439 .FromJust(); | |
1440 const char* code = | |
1441 "obj.x = 17; " | |
1442 "Object.defineProperty(obj, 'x', {value: 42, configurable: true});" | |
1443 "obj.x;"; | |
1444 CHECK_EQ(17, v8_compile(code) | |
1445 ->Run(env.local()) | |
1446 .ToLocalChecked() | |
1447 ->Int32Value(env.local()) | |
1448 .FromJust()); | |
1449 } | |
1450 | |
1451 // Check that the descriptor passed to the callback is writable. | |
1452 namespace { | |
1453 void CheckWritablePropertyDefineCallback( | |
1454 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1455 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1456 CHECK(desc.has_writable()); | |
1457 CHECK(desc.writable()); | |
1458 | |
1459 // intercept the callback by setting a non-empty handle | |
1460 info.GetReturnValue().Set(name); | |
1461 } | |
1462 } // namespace | |
1463 THREADED_TEST(PropertyDefinerCallbackWritable) { | |
1464 v8::HandleScope scope(CcTest::isolate()); | |
1465 LocalContext env; | |
1466 v8::Local<v8::FunctionTemplate> templ = | |
1467 v8::FunctionTemplate::New(CcTest::isolate()); | |
1468 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1469 0, 0, 0, 0, 0, CheckWritablePropertyDefineCallback)); | |
1470 env->Global() | |
1471 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1472 .ToLocalChecked() | |
1473 ->NewInstance(env.local()) | |
1474 .ToLocalChecked()) | |
1475 .FromJust(); | |
1476 const char* code = | |
1477 "obj.x = 17; " | |
1478 "Object.defineProperty(obj, 'x', {value: 42, writable: true});" | |
1479 "obj.x;"; | |
1480 CHECK_EQ(17, v8_compile(code) | |
1481 ->Run(env.local()) | |
1482 .ToLocalChecked() | |
1483 ->Int32Value(env.local()) | |
1484 .FromJust()); | |
1485 } | |
1486 | |
1487 // Check that the descriptor passed to the callback has a getter. | |
1488 namespace { | |
1489 void CheckGetterPropertyDefineCallback( | |
1490 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1491 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1492 CHECK(desc.has_get()); | |
1493 CHECK(!desc.has_set()); | |
1494 // intercept the callback by setting a non-empty handle | |
1495 info.GetReturnValue().Set(name); | |
1496 } | |
1497 } // namespace | |
1498 THREADED_TEST(PropertyDefinerCallbackWithGetter) { | |
1499 v8::HandleScope scope(CcTest::isolate()); | |
1500 LocalContext env; | |
1501 v8::Local<v8::FunctionTemplate> templ = | |
1502 v8::FunctionTemplate::New(CcTest::isolate()); | |
1503 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1504 0, 0, 0, 0, 0, CheckGetterPropertyDefineCallback)); | |
1505 env->Global() | |
1506 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1507 .ToLocalChecked() | |
1508 ->NewInstance(env.local()) | |
1509 .ToLocalChecked()) | |
1510 .FromJust(); | |
1511 const char* code = | |
1512 "obj.x = 17;" | |
1513 "Object.defineProperty(obj, 'x', {get: function() {return 42;}});" | |
1514 "obj.x;"; | |
1515 CHECK_EQ(17, v8_compile(code) | |
1516 ->Run(env.local()) | |
1517 .ToLocalChecked() | |
1518 ->Int32Value(env.local()) | |
1519 .FromJust()); | |
1520 } | |
1521 | |
1522 // Check that the descriptor passed to the callback has a setter. | |
1523 namespace { | |
1524 void CheckSetterPropertyDefineCallback( | |
1525 Local<Name> name, const v8::PropertyDescriptor& desc, | |
1526 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
1527 CHECK(desc.has_set()); | |
1528 CHECK(!desc.has_get()); | |
1529 // intercept the callback by setting a non-empty handle | |
1530 info.GetReturnValue().Set(name); | |
1531 } | |
1532 } // namespace | |
1533 THREADED_TEST(PropertyDefinerCallbackWithSetter) { | |
1534 v8::HandleScope scope(CcTest::isolate()); | |
1535 LocalContext env; | |
1536 v8::Local<v8::FunctionTemplate> templ = | |
1537 v8::FunctionTemplate::New(CcTest::isolate()); | |
1538 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | |
1539 0, 0, 0, 0, 0, CheckSetterPropertyDefineCallback)); | |
1540 env->Global() | |
1541 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) | |
1542 .ToLocalChecked() | |
1543 ->NewInstance(env.local()) | |
1544 .ToLocalChecked()) | |
1545 .FromJust(); | |
1546 const char* code = | |
1547 "Object.defineProperty(obj, 'x', {set: function() {return 42;}});" | |
1548 "obj.x = 17;"; | |
1549 CHECK_EQ(17, v8_compile(code) | |
1550 ->Run(env.local()) | |
1551 .ToLocalChecked() | |
1552 ->Int32Value(env.local()) | |
1553 .FromJust()); | |
1554 } | |
1555 | 1106 |
1556 int echo_indexed_call_count = 0; | 1107 int echo_indexed_call_count = 0; |
1557 | 1108 |
1558 | 1109 |
1559 static void EchoIndexedProperty( | 1110 static void EchoIndexedProperty( |
1560 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { | 1111 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { |
1561 ApiTestFuzzer::Fuzz(); | 1112 ApiTestFuzzer::Fuzz(); |
1562 CHECK(v8_num(637) | 1113 CHECK(v8_num(637) |
1563 ->Equals(info.GetIsolate()->GetCurrentContext(), info.Data()) | 1114 ->Equals(info.GetIsolate()->GetCurrentContext(), info.Data()) |
1564 .FromJust()); | 1115 .FromJust()); |
(...skipping 27 matching lines...) Expand all Loading... |
1592 THREADED_TEST(PropertyHandlerInPrototype) { | 1143 THREADED_TEST(PropertyHandlerInPrototype) { |
1593 LocalContext env; | 1144 LocalContext env; |
1594 v8::Isolate* isolate = env->GetIsolate(); | 1145 v8::Isolate* isolate = env->GetIsolate(); |
1595 v8::HandleScope scope(isolate); | 1146 v8::HandleScope scope(isolate); |
1596 | 1147 |
1597 // Set up a prototype chain with three interceptors. | 1148 // Set up a prototype chain with three interceptors. |
1598 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 1149 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
1599 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 1150 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
1600 CheckThisIndexedPropertyHandler, CheckThisIndexedPropertySetter, | 1151 CheckThisIndexedPropertyHandler, CheckThisIndexedPropertySetter, |
1601 CheckThisIndexedPropertyQuery, CheckThisIndexedPropertyDeleter, | 1152 CheckThisIndexedPropertyQuery, CheckThisIndexedPropertyDeleter, |
1602 CheckThisIndexedPropertyEnumerator, CheckThisIndexedPropertyDefiner)); | 1153 CheckThisIndexedPropertyEnumerator)); |
1603 | 1154 |
1604 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | 1155 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
1605 CheckThisNamedPropertyHandler, CheckThisNamedPropertySetter, | 1156 CheckThisNamedPropertyHandler, CheckThisNamedPropertySetter, |
1606 CheckThisNamedPropertyQuery, CheckThisNamedPropertyDeleter, | 1157 CheckThisNamedPropertyQuery, CheckThisNamedPropertyDeleter, |
1607 CheckThisNamedPropertyEnumerator, CheckThisNamedPropertyDefiner)); | 1158 CheckThisNamedPropertyEnumerator)); |
1608 | 1159 |
1609 bottom = templ->GetFunction(env.local()) | 1160 bottom = templ->GetFunction(env.local()) |
1610 .ToLocalChecked() | 1161 .ToLocalChecked() |
1611 ->NewInstance(env.local()) | 1162 ->NewInstance(env.local()) |
1612 .ToLocalChecked(); | 1163 .ToLocalChecked(); |
1613 Local<v8::Object> top = templ->GetFunction(env.local()) | 1164 Local<v8::Object> top = templ->GetFunction(env.local()) |
1614 .ToLocalChecked() | 1165 .ToLocalChecked() |
1615 ->NewInstance(env.local()) | 1166 ->NewInstance(env.local()) |
1616 .ToLocalChecked(); | 1167 .ToLocalChecked(); |
1617 Local<v8::Object> middle = templ->GetFunction(env.local()) | 1168 Local<v8::Object> middle = templ->GetFunction(env.local()) |
(...skipping 16 matching lines...) Expand all Loading... |
1634 // Indexed and named query. | 1185 // Indexed and named query. |
1635 CompileRun("0 in obj"); | 1186 CompileRun("0 in obj"); |
1636 CompileRun("'x' in obj"); | 1187 CompileRun("'x' in obj"); |
1637 | 1188 |
1638 // Indexed and named deleter. | 1189 // Indexed and named deleter. |
1639 CompileRun("delete obj[0]"); | 1190 CompileRun("delete obj[0]"); |
1640 CompileRun("delete obj.x"); | 1191 CompileRun("delete obj.x"); |
1641 | 1192 |
1642 // Enumerators. | 1193 // Enumerators. |
1643 CompileRun("for (var p in obj) ;"); | 1194 CompileRun("for (var p in obj) ;"); |
1644 | |
1645 // Indexed and named definer. | |
1646 CompileRun("Object.defineProperty(obj, 2, {});"); | |
1647 CompileRun("Object.defineProperty(obj, 'z', {});"); | |
1648 } | 1195 } |
1649 | 1196 |
1650 | 1197 |
1651 bool is_bootstrapping = false; | 1198 bool is_bootstrapping = false; |
1652 static void PrePropertyHandlerGet( | 1199 static void PrePropertyHandlerGet( |
1653 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { | 1200 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
1654 ApiTestFuzzer::Fuzz(); | 1201 ApiTestFuzzer::Fuzz(); |
1655 if (!is_bootstrapping && | 1202 if (!is_bootstrapping && |
1656 v8_str("pre") | 1203 v8_str("pre") |
1657 ->Equals(info.GetIsolate()->GetCurrentContext(), key) | 1204 ->Equals(info.GetIsolate()->GetCurrentContext(), key) |
(...skipping 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4438 ->Set(env.local(), v8_str("Fun"), | 3985 ->Set(env.local(), v8_str("Fun"), |
4439 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 3986 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
4440 .FromJust()); | 3987 .FromJust()); |
4441 | 3988 |
4442 CompileRun( | 3989 CompileRun( |
4443 "var f = new Fun();" | 3990 "var f = new Fun();" |
4444 "Number.prototype.__proto__ = f;" | 3991 "Number.prototype.__proto__ = f;" |
4445 "var a = 42;" | 3992 "var a = 42;" |
4446 "for (var i = 0; i<3; i++) { a.foo; }"); | 3993 "for (var i = 0; i<3; i++) { a.foo; }"); |
4447 } | 3994 } |
OLD | NEW |