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 |
242 void CheckThisIndexedPropertySetter( | 262 void CheckThisIndexedPropertySetter( |
243 uint32_t index, Local<Value> value, | 263 uint32_t index, Local<Value> value, |
244 const v8::PropertyCallbackInfo<v8::Value>& info) { | 264 const v8::PropertyCallbackInfo<v8::Value>& info) { |
245 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); | 265 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); |
246 ApiTestFuzzer::Fuzz(); | 266 ApiTestFuzzer::Fuzz(); |
247 CHECK(info.This() | 267 CHECK(info.This() |
248 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) | 268 ->Equals(info.GetIsolate()->GetCurrentContext(), bottom) |
249 .FromJust()); | 269 .FromJust()); |
250 } | 270 } |
251 | 271 |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 .ToLocalChecked() | 1212 .ToLocalChecked() |
1193 ->BooleanValue(env.local()) | 1213 ->BooleanValue(env.local()) |
1194 .FromJust()); | 1214 .FromJust()); |
1195 CHECK(v8_compile("delete obj.myProperty") | 1215 CHECK(v8_compile("delete obj.myProperty") |
1196 ->Run(env.local()) | 1216 ->Run(env.local()) |
1197 .ToLocalChecked() | 1217 .ToLocalChecked() |
1198 ->BooleanValue(env.local()) | 1218 ->BooleanValue(env.local()) |
1199 .FromJust()); | 1219 .FromJust()); |
1200 } | 1220 } |
1201 | 1221 |
| 1222 namespace { |
| 1223 void NotInterceptingPropertyDefineCallback( |
| 1224 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1225 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1226 // Do not intercept by not calling info.GetReturnValue().Set() |
| 1227 } |
| 1228 |
| 1229 void InterceptingPropertyDefineCallback( |
| 1230 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1231 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1232 // intercept the callback by setting a non-empty handle |
| 1233 info.GetReturnValue().Set(name); |
| 1234 } |
| 1235 |
| 1236 void CheckDescriptorInDefineCallback( |
| 1237 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1238 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1239 CHECK(!desc.has_writable()); |
| 1240 CHECK(!desc.has_value()); |
| 1241 CHECK(!desc.has_enumerable()); |
| 1242 CHECK(desc.has_configurable()); |
| 1243 CHECK(!desc.configurable()); |
| 1244 CHECK(desc.has_get()); |
| 1245 CHECK(desc.get()->IsFunction()); |
| 1246 CHECK(desc.has_set()); |
| 1247 CHECK(desc.set()->IsUndefined()); |
| 1248 // intercept the callback by setting a non-empty handle |
| 1249 info.GetReturnValue().Set(name); |
| 1250 } |
| 1251 } // namespace |
| 1252 |
| 1253 THREADED_TEST(PropertyDefinerCallback) { |
| 1254 v8::HandleScope scope(CcTest::isolate()); |
| 1255 LocalContext env; |
| 1256 |
| 1257 { // Intercept defineProperty() |
| 1258 v8::Local<v8::FunctionTemplate> templ = |
| 1259 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1260 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1261 0, 0, 0, 0, 0, NotInterceptingPropertyDefineCallback)); |
| 1262 env->Global() |
| 1263 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1264 .ToLocalChecked() |
| 1265 ->NewInstance(env.local()) |
| 1266 .ToLocalChecked()) |
| 1267 .FromJust(); |
| 1268 const char* code = |
| 1269 "obj.x = 17; " |
| 1270 "Object.defineProperty(obj, 'x', {value: 42});" |
| 1271 "obj.x;"; |
| 1272 CHECK_EQ(42, v8_compile(code) |
| 1273 ->Run(env.local()) |
| 1274 .ToLocalChecked() |
| 1275 ->Int32Value(env.local()) |
| 1276 .FromJust()); |
| 1277 } |
| 1278 |
| 1279 { // Intercept defineProperty() for correct accessor descriptor |
| 1280 v8::Local<v8::FunctionTemplate> templ = |
| 1281 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1282 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1283 0, 0, 0, 0, 0, CheckDescriptorInDefineCallback)); |
| 1284 env->Global() |
| 1285 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1286 .ToLocalChecked() |
| 1287 ->NewInstance(env.local()) |
| 1288 .ToLocalChecked()) |
| 1289 .FromJust(); |
| 1290 const char* code = |
| 1291 "obj.x = 17; " |
| 1292 "Object.defineProperty(obj, 'x', {" |
| 1293 "get: function(){ return 42; }, " |
| 1294 "set: undefined," |
| 1295 "configurable: 0" |
| 1296 "});" |
| 1297 "obj.x;"; |
| 1298 CHECK_EQ(17, v8_compile(code) |
| 1299 ->Run(env.local()) |
| 1300 .ToLocalChecked() |
| 1301 ->Int32Value(env.local()) |
| 1302 .FromJust()); |
| 1303 } |
| 1304 |
| 1305 { // Do not intercept defineProperty() |
| 1306 v8::Local<v8::FunctionTemplate> templ2 = |
| 1307 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1308 templ2->InstanceTemplate()->SetHandler( |
| 1309 v8::NamedPropertyHandlerConfiguration( |
| 1310 0, 0, 0, 0, 0, InterceptingPropertyDefineCallback)); |
| 1311 env->Global() |
| 1312 ->Set(env.local(), v8_str("obj"), templ2->GetFunction(env.local()) |
| 1313 .ToLocalChecked() |
| 1314 ->NewInstance(env.local()) |
| 1315 .ToLocalChecked()) |
| 1316 .FromJust(); |
| 1317 |
| 1318 const char* code = |
| 1319 "obj.x = 17; " |
| 1320 "Object.defineProperty(obj, 'x', {value: 42});" |
| 1321 "obj.x;"; |
| 1322 CHECK_EQ(17, v8_compile(code) |
| 1323 ->Run(env.local()) |
| 1324 .ToLocalChecked() |
| 1325 ->Int32Value(env.local()) |
| 1326 .FromJust()); |
| 1327 } |
| 1328 } |
| 1329 |
| 1330 namespace { |
| 1331 void NotInterceptingPropertyDefineCallbackIndexed( |
| 1332 uint32_t index, const v8::PropertyDescriptor& desc, |
| 1333 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1334 // Do not intercept by not calling info.GetReturnValue().Set() |
| 1335 } |
| 1336 |
| 1337 void InterceptingPropertyDefineCallbackIndexed( |
| 1338 uint32_t index, const v8::PropertyDescriptor& desc, |
| 1339 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1340 // intercept the callback by setting a non-empty handle |
| 1341 info.GetReturnValue().Set(index); |
| 1342 } |
| 1343 |
| 1344 void CheckDescriptorInDefineCallbackIndexed( |
| 1345 uint32_t index, const v8::PropertyDescriptor& desc, |
| 1346 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1347 CHECK(!desc.has_writable()); |
| 1348 CHECK(!desc.has_value()); |
| 1349 CHECK(desc.has_enumerable()); |
| 1350 CHECK(desc.enumerable()); |
| 1351 CHECK(!desc.has_configurable()); |
| 1352 CHECK(desc.has_get()); |
| 1353 CHECK(desc.get()->IsFunction()); |
| 1354 CHECK(desc.has_set()); |
| 1355 CHECK(desc.set()->IsUndefined()); |
| 1356 // intercept the callback by setting a non-empty handle |
| 1357 info.GetReturnValue().Set(index); |
| 1358 } |
| 1359 } // namespace |
| 1360 |
| 1361 THREADED_TEST(PropertyDefinerCallbackIndexed) { |
| 1362 v8::HandleScope scope(CcTest::isolate()); |
| 1363 LocalContext env; |
| 1364 |
| 1365 { // Intercept defineProperty() |
| 1366 v8::Local<v8::FunctionTemplate> templ = |
| 1367 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1368 templ->InstanceTemplate()->SetHandler( |
| 1369 v8::IndexedPropertyHandlerConfiguration( |
| 1370 0, 0, 0, 0, 0, NotInterceptingPropertyDefineCallbackIndexed)); |
| 1371 env->Global() |
| 1372 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1373 .ToLocalChecked() |
| 1374 ->NewInstance(env.local()) |
| 1375 .ToLocalChecked()) |
| 1376 .FromJust(); |
| 1377 const char* code = |
| 1378 "obj[2] = 17; " |
| 1379 "Object.defineProperty(obj, 2, {value: 42});" |
| 1380 "obj[2];"; |
| 1381 CHECK_EQ(42, v8_compile(code) |
| 1382 ->Run(env.local()) |
| 1383 .ToLocalChecked() |
| 1384 ->Int32Value(env.local()) |
| 1385 .FromJust()); |
| 1386 } |
| 1387 |
| 1388 { // Intercept defineProperty() for correct accessor descriptor |
| 1389 v8::Local<v8::FunctionTemplate> templ = |
| 1390 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1391 templ->InstanceTemplate()->SetHandler( |
| 1392 v8::IndexedPropertyHandlerConfiguration( |
| 1393 0, 0, 0, 0, 0, CheckDescriptorInDefineCallbackIndexed)); |
| 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[2] = 17; " |
| 1402 "Object.defineProperty(obj, 2, {" |
| 1403 "get: function(){ return 42; }, " |
| 1404 "set: undefined," |
| 1405 "enumerable: true" |
| 1406 "});" |
| 1407 "obj[2];"; |
| 1408 CHECK_EQ(17, v8_compile(code) |
| 1409 ->Run(env.local()) |
| 1410 .ToLocalChecked() |
| 1411 ->Int32Value(env.local()) |
| 1412 .FromJust()); |
| 1413 } |
| 1414 |
| 1415 { // Do not intercept defineProperty() |
| 1416 v8::Local<v8::FunctionTemplate> templ2 = |
| 1417 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1418 templ2->InstanceTemplate()->SetHandler( |
| 1419 v8::IndexedPropertyHandlerConfiguration( |
| 1420 0, 0, 0, 0, 0, InterceptingPropertyDefineCallbackIndexed)); |
| 1421 env->Global() |
| 1422 ->Set(env.local(), v8_str("obj"), templ2->GetFunction(env.local()) |
| 1423 .ToLocalChecked() |
| 1424 ->NewInstance(env.local()) |
| 1425 .ToLocalChecked()) |
| 1426 .FromJust(); |
| 1427 |
| 1428 const char* code = |
| 1429 "obj[2] = 17; " |
| 1430 "Object.defineProperty(obj, 2, {value: 42});" |
| 1431 "obj[2];"; |
| 1432 CHECK_EQ(17, v8_compile(code) |
| 1433 ->Run(env.local()) |
| 1434 .ToLocalChecked() |
| 1435 ->Int32Value(env.local()) |
| 1436 .FromJust()); |
| 1437 } |
| 1438 } |
| 1439 |
| 1440 // Test that freeze() is intercepted. |
| 1441 THREADED_TEST(PropertyDefinerCallbackForFreeze) { |
| 1442 v8::HandleScope scope(CcTest::isolate()); |
| 1443 LocalContext env; |
| 1444 v8::Local<v8::FunctionTemplate> templ = |
| 1445 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1446 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1447 0, 0, 0, 0, 0, InterceptingPropertyDefineCallback)); |
| 1448 env->Global() |
| 1449 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1450 .ToLocalChecked() |
| 1451 ->NewInstance(env.local()) |
| 1452 .ToLocalChecked()) |
| 1453 .FromJust(); |
| 1454 const char* code = |
| 1455 "obj.x = 17; " |
| 1456 "Object.freeze(obj.x); " |
| 1457 "Object.isFrozen(obj.x);"; |
| 1458 |
| 1459 CHECK(v8_compile(code) |
| 1460 ->Run(env.local()) |
| 1461 .ToLocalChecked() |
| 1462 ->BooleanValue(env.local()) |
| 1463 .FromJust()); |
| 1464 } |
| 1465 |
| 1466 // Check that the descriptor passed to the callback is enumerable. |
| 1467 namespace { |
| 1468 void CheckEnumerablePropertyDefineCallback( |
| 1469 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1470 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1471 CHECK(desc.has_value()); |
| 1472 CHECK_EQ(42, desc.value() |
| 1473 ->Int32Value(info.GetIsolate()->GetCurrentContext()) |
| 1474 .FromJust()); |
| 1475 CHECK(desc.has_enumerable()); |
| 1476 CHECK(desc.enumerable()); |
| 1477 CHECK(!desc.has_writable()); |
| 1478 |
| 1479 // intercept the callback by setting a non-empty handle |
| 1480 info.GetReturnValue().Set(name); |
| 1481 } |
| 1482 } // namespace |
| 1483 THREADED_TEST(PropertyDefinerCallbackEnumerable) { |
| 1484 v8::HandleScope scope(CcTest::isolate()); |
| 1485 LocalContext env; |
| 1486 v8::Local<v8::FunctionTemplate> templ = |
| 1487 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1488 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1489 0, 0, 0, 0, 0, CheckEnumerablePropertyDefineCallback)); |
| 1490 env->Global() |
| 1491 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1492 .ToLocalChecked() |
| 1493 ->NewInstance(env.local()) |
| 1494 .ToLocalChecked()) |
| 1495 .FromJust(); |
| 1496 const char* code = |
| 1497 "obj.x = 17; " |
| 1498 "Object.defineProperty(obj, 'x', {value: 42, enumerable: true});" |
| 1499 "obj.x;"; |
| 1500 CHECK_EQ(17, v8_compile(code) |
| 1501 ->Run(env.local()) |
| 1502 .ToLocalChecked() |
| 1503 ->Int32Value(env.local()) |
| 1504 .FromJust()); |
| 1505 } |
| 1506 |
| 1507 // Check that the descriptor passed to the callback is configurable. |
| 1508 namespace { |
| 1509 void CheckConfigurablePropertyDefineCallback( |
| 1510 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1511 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1512 CHECK(desc.has_value()); |
| 1513 CHECK_EQ(42, desc.value() |
| 1514 ->Int32Value(info.GetIsolate()->GetCurrentContext()) |
| 1515 .FromJust()); |
| 1516 CHECK(desc.has_configurable()); |
| 1517 CHECK(desc.configurable()); |
| 1518 |
| 1519 // intercept the callback by setting a non-empty handle |
| 1520 info.GetReturnValue().Set(name); |
| 1521 } |
| 1522 } // namespace |
| 1523 THREADED_TEST(PropertyDefinerCallbackConfigurable) { |
| 1524 v8::HandleScope scope(CcTest::isolate()); |
| 1525 LocalContext env; |
| 1526 v8::Local<v8::FunctionTemplate> templ = |
| 1527 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1528 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1529 0, 0, 0, 0, 0, CheckConfigurablePropertyDefineCallback)); |
| 1530 env->Global() |
| 1531 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1532 .ToLocalChecked() |
| 1533 ->NewInstance(env.local()) |
| 1534 .ToLocalChecked()) |
| 1535 .FromJust(); |
| 1536 const char* code = |
| 1537 "obj.x = 17; " |
| 1538 "Object.defineProperty(obj, 'x', {value: 42, configurable: true});" |
| 1539 "obj.x;"; |
| 1540 CHECK_EQ(17, v8_compile(code) |
| 1541 ->Run(env.local()) |
| 1542 .ToLocalChecked() |
| 1543 ->Int32Value(env.local()) |
| 1544 .FromJust()); |
| 1545 } |
| 1546 |
| 1547 // Check that the descriptor passed to the callback is writable. |
| 1548 namespace { |
| 1549 void CheckWritablePropertyDefineCallback( |
| 1550 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1551 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1552 CHECK(desc.has_writable()); |
| 1553 CHECK(desc.writable()); |
| 1554 |
| 1555 // intercept the callback by setting a non-empty handle |
| 1556 info.GetReturnValue().Set(name); |
| 1557 } |
| 1558 } // namespace |
| 1559 THREADED_TEST(PropertyDefinerCallbackWritable) { |
| 1560 v8::HandleScope scope(CcTest::isolate()); |
| 1561 LocalContext env; |
| 1562 v8::Local<v8::FunctionTemplate> templ = |
| 1563 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1564 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1565 0, 0, 0, 0, 0, CheckWritablePropertyDefineCallback)); |
| 1566 env->Global() |
| 1567 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1568 .ToLocalChecked() |
| 1569 ->NewInstance(env.local()) |
| 1570 .ToLocalChecked()) |
| 1571 .FromJust(); |
| 1572 const char* code = |
| 1573 "obj.x = 17; " |
| 1574 "Object.defineProperty(obj, 'x', {value: 42, writable: true});" |
| 1575 "obj.x;"; |
| 1576 CHECK_EQ(17, v8_compile(code) |
| 1577 ->Run(env.local()) |
| 1578 .ToLocalChecked() |
| 1579 ->Int32Value(env.local()) |
| 1580 .FromJust()); |
| 1581 } |
| 1582 |
| 1583 // Check that the descriptor passed to the callback has a getter. |
| 1584 namespace { |
| 1585 void CheckGetterPropertyDefineCallback( |
| 1586 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1587 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1588 CHECK(desc.has_get()); |
| 1589 CHECK(!desc.has_set()); |
| 1590 // intercept the callback by setting a non-empty handle |
| 1591 info.GetReturnValue().Set(name); |
| 1592 } |
| 1593 } // namespace |
| 1594 THREADED_TEST(PropertyDefinerCallbackWithGetter) { |
| 1595 v8::HandleScope scope(CcTest::isolate()); |
| 1596 LocalContext env; |
| 1597 v8::Local<v8::FunctionTemplate> templ = |
| 1598 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1599 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1600 0, 0, 0, 0, 0, CheckGetterPropertyDefineCallback)); |
| 1601 env->Global() |
| 1602 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1603 .ToLocalChecked() |
| 1604 ->NewInstance(env.local()) |
| 1605 .ToLocalChecked()) |
| 1606 .FromJust(); |
| 1607 const char* code = |
| 1608 "obj.x = 17;" |
| 1609 "Object.defineProperty(obj, 'x', {get: function() {return 42;}});" |
| 1610 "obj.x;"; |
| 1611 CHECK_EQ(17, v8_compile(code) |
| 1612 ->Run(env.local()) |
| 1613 .ToLocalChecked() |
| 1614 ->Int32Value(env.local()) |
| 1615 .FromJust()); |
| 1616 } |
| 1617 |
| 1618 // Check that the descriptor passed to the callback has a setter. |
| 1619 namespace { |
| 1620 void CheckSetterPropertyDefineCallback( |
| 1621 Local<Name> name, const v8::PropertyDescriptor& desc, |
| 1622 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1623 CHECK(desc.has_set()); |
| 1624 CHECK(!desc.has_get()); |
| 1625 // intercept the callback by setting a non-empty handle |
| 1626 info.GetReturnValue().Set(name); |
| 1627 } |
| 1628 } // namespace |
| 1629 THREADED_TEST(PropertyDefinerCallbackWithSetter) { |
| 1630 v8::HandleScope scope(CcTest::isolate()); |
| 1631 LocalContext env; |
| 1632 v8::Local<v8::FunctionTemplate> templ = |
| 1633 v8::FunctionTemplate::New(CcTest::isolate()); |
| 1634 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
| 1635 0, 0, 0, 0, 0, CheckSetterPropertyDefineCallback)); |
| 1636 env->Global() |
| 1637 ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local()) |
| 1638 .ToLocalChecked() |
| 1639 ->NewInstance(env.local()) |
| 1640 .ToLocalChecked()) |
| 1641 .FromJust(); |
| 1642 const char* code = |
| 1643 "Object.defineProperty(obj, 'x', {set: function() {return 42;}});" |
| 1644 "obj.x = 17;"; |
| 1645 CHECK_EQ(17, v8_compile(code) |
| 1646 ->Run(env.local()) |
| 1647 .ToLocalChecked() |
| 1648 ->Int32Value(env.local()) |
| 1649 .FromJust()); |
| 1650 } |
1202 | 1651 |
1203 int echo_indexed_call_count = 0; | 1652 int echo_indexed_call_count = 0; |
1204 | 1653 |
1205 | 1654 |
1206 static void EchoIndexedProperty( | 1655 static void EchoIndexedProperty( |
1207 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { | 1656 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { |
1208 ApiTestFuzzer::Fuzz(); | 1657 ApiTestFuzzer::Fuzz(); |
1209 CHECK(v8_num(637) | 1658 CHECK(v8_num(637) |
1210 ->Equals(info.GetIsolate()->GetCurrentContext(), info.Data()) | 1659 ->Equals(info.GetIsolate()->GetCurrentContext(), info.Data()) |
1211 .FromJust()); | 1660 .FromJust()); |
(...skipping 27 matching lines...) Expand all Loading... |
1239 THREADED_TEST(PropertyHandlerInPrototype) { | 1688 THREADED_TEST(PropertyHandlerInPrototype) { |
1240 LocalContext env; | 1689 LocalContext env; |
1241 v8::Isolate* isolate = env->GetIsolate(); | 1690 v8::Isolate* isolate = env->GetIsolate(); |
1242 v8::HandleScope scope(isolate); | 1691 v8::HandleScope scope(isolate); |
1243 | 1692 |
1244 // Set up a prototype chain with three interceptors. | 1693 // Set up a prototype chain with three interceptors. |
1245 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 1694 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
1246 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 1695 templ->InstanceTemplate()->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
1247 CheckThisIndexedPropertyHandler, CheckThisIndexedPropertySetter, | 1696 CheckThisIndexedPropertyHandler, CheckThisIndexedPropertySetter, |
1248 CheckThisIndexedPropertyQuery, CheckThisIndexedPropertyDeleter, | 1697 CheckThisIndexedPropertyQuery, CheckThisIndexedPropertyDeleter, |
1249 CheckThisIndexedPropertyEnumerator)); | 1698 CheckThisIndexedPropertyEnumerator, CheckThisIndexedPropertyDefiner)); |
1250 | 1699 |
1251 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( | 1700 templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration( |
1252 CheckThisNamedPropertyHandler, CheckThisNamedPropertySetter, | 1701 CheckThisNamedPropertyHandler, CheckThisNamedPropertySetter, |
1253 CheckThisNamedPropertyQuery, CheckThisNamedPropertyDeleter, | 1702 CheckThisNamedPropertyQuery, CheckThisNamedPropertyDeleter, |
1254 CheckThisNamedPropertyEnumerator)); | 1703 CheckThisNamedPropertyEnumerator, CheckThisNamedPropertyDefiner)); |
1255 | 1704 |
1256 bottom = templ->GetFunction(env.local()) | 1705 bottom = templ->GetFunction(env.local()) |
1257 .ToLocalChecked() | 1706 .ToLocalChecked() |
1258 ->NewInstance(env.local()) | 1707 ->NewInstance(env.local()) |
1259 .ToLocalChecked(); | 1708 .ToLocalChecked(); |
1260 Local<v8::Object> top = templ->GetFunction(env.local()) | 1709 Local<v8::Object> top = templ->GetFunction(env.local()) |
1261 .ToLocalChecked() | 1710 .ToLocalChecked() |
1262 ->NewInstance(env.local()) | 1711 ->NewInstance(env.local()) |
1263 .ToLocalChecked(); | 1712 .ToLocalChecked(); |
1264 Local<v8::Object> middle = templ->GetFunction(env.local()) | 1713 Local<v8::Object> middle = templ->GetFunction(env.local()) |
(...skipping 16 matching lines...) Expand all Loading... |
1281 // Indexed and named query. | 1730 // Indexed and named query. |
1282 CompileRun("0 in obj"); | 1731 CompileRun("0 in obj"); |
1283 CompileRun("'x' in obj"); | 1732 CompileRun("'x' in obj"); |
1284 | 1733 |
1285 // Indexed and named deleter. | 1734 // Indexed and named deleter. |
1286 CompileRun("delete obj[0]"); | 1735 CompileRun("delete obj[0]"); |
1287 CompileRun("delete obj.x"); | 1736 CompileRun("delete obj.x"); |
1288 | 1737 |
1289 // Enumerators. | 1738 // Enumerators. |
1290 CompileRun("for (var p in obj) ;"); | 1739 CompileRun("for (var p in obj) ;"); |
| 1740 |
| 1741 // Indexed and named definer. |
| 1742 CompileRun("Object.defineProperty(obj, 2, {});"); |
| 1743 CompileRun("Object.defineProperty(obj, 'z', {});"); |
1291 } | 1744 } |
1292 | 1745 |
1293 | 1746 |
1294 bool is_bootstrapping = false; | 1747 bool is_bootstrapping = false; |
1295 static void PrePropertyHandlerGet( | 1748 static void PrePropertyHandlerGet( |
1296 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { | 1749 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
1297 ApiTestFuzzer::Fuzz(); | 1750 ApiTestFuzzer::Fuzz(); |
1298 if (!is_bootstrapping && | 1751 if (!is_bootstrapping && |
1299 v8_str("pre") | 1752 v8_str("pre") |
1300 ->Equals(info.GetIsolate()->GetCurrentContext(), key) | 1753 ->Equals(info.GetIsolate()->GetCurrentContext(), key) |
(...skipping 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4081 ->Set(env.local(), v8_str("Fun"), | 4534 ->Set(env.local(), v8_str("Fun"), |
4082 fun_templ->GetFunction(env.local()).ToLocalChecked()) | 4535 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
4083 .FromJust()); | 4536 .FromJust()); |
4084 | 4537 |
4085 CompileRun( | 4538 CompileRun( |
4086 "var f = new Fun();" | 4539 "var f = new Fun();" |
4087 "Number.prototype.__proto__ = f;" | 4540 "Number.prototype.__proto__ = f;" |
4088 "var a = 42;" | 4541 "var a = 42;" |
4089 "for (var i = 0; i<3; i++) { a.foo; }"); | 4542 "for (var i = 0; i<3; i++) { a.foo; }"); |
4090 } | 4543 } |
OLD | NEW |