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 "src/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) { | 1362 MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) { |
1363 Isolate* isolate = it->isolate(); | 1363 Isolate* isolate = it->isolate(); |
1364 Handle<Object> structure = it->GetAccessors(); | 1364 Handle<Object> structure = it->GetAccessors(); |
1365 Handle<Object> receiver = it->GetReceiver(); | 1365 Handle<Object> receiver = it->GetReceiver(); |
1366 | 1366 |
1367 // We should never get here to initialize a const with the hole value since a | 1367 // We should never get here to initialize a const with the hole value since a |
1368 // const declaration would conflict with the getter. | 1368 // const declaration would conflict with the getter. |
1369 DCHECK(!structure->IsForeign()); | 1369 DCHECK(!structure->IsForeign()); |
1370 | 1370 |
1371 // API style callbacks. | 1371 // API style callbacks. |
| 1372 Handle<JSObject> holder = it->GetHolder<JSObject>(); |
1372 if (structure->IsAccessorInfo()) { | 1373 if (structure->IsAccessorInfo()) { |
1373 Handle<JSObject> holder = it->GetHolder<JSObject>(); | |
1374 Handle<Name> name = it->GetName(); | 1374 Handle<Name> name = it->GetName(); |
1375 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); | 1375 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); |
1376 if (!info->IsCompatibleReceiver(*receiver)) { | 1376 if (!info->IsCompatibleReceiver(*receiver)) { |
1377 THROW_NEW_ERROR(isolate, | 1377 THROW_NEW_ERROR(isolate, |
1378 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, | 1378 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
1379 name, receiver), | 1379 name, receiver), |
1380 Object); | 1380 Object); |
1381 } | 1381 } |
1382 | 1382 |
1383 v8::AccessorNameGetterCallback call_fun = | 1383 v8::AccessorNameGetterCallback call_fun = |
(...skipping 22 matching lines...) Expand all Loading... |
1406 } | 1406 } |
1407 | 1407 |
1408 // AccessorPair with 'cached' private property. | 1408 // AccessorPair with 'cached' private property. |
1409 if (it->TryLookupCachedProperty()) { | 1409 if (it->TryLookupCachedProperty()) { |
1410 return Object::GetProperty(it); | 1410 return Object::GetProperty(it); |
1411 } | 1411 } |
1412 | 1412 |
1413 // Regular accessor. | 1413 // Regular accessor. |
1414 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); | 1414 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); |
1415 if (getter->IsFunctionTemplateInfo()) { | 1415 if (getter->IsFunctionTemplateInfo()) { |
| 1416 SaveContext save(isolate); |
| 1417 isolate->set_context(*holder->GetCreationContext()); |
1416 return Builtins::InvokeApiFunction( | 1418 return Builtins::InvokeApiFunction( |
1417 isolate, false, Handle<FunctionTemplateInfo>::cast(getter), receiver, 0, | 1419 isolate, false, Handle<FunctionTemplateInfo>::cast(getter), receiver, 0, |
1418 nullptr, isolate->factory()->undefined_value()); | 1420 nullptr, isolate->factory()->undefined_value()); |
1419 } else if (getter->IsCallable()) { | 1421 } else if (getter->IsCallable()) { |
1420 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 1422 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
1421 return Object::GetPropertyWithDefinedGetter( | 1423 return Object::GetPropertyWithDefinedGetter( |
1422 receiver, Handle<JSReceiver>::cast(getter)); | 1424 receiver, Handle<JSReceiver>::cast(getter)); |
1423 } | 1425 } |
1424 // Getter is not a function. | 1426 // Getter is not a function. |
1425 return isolate->factory()->undefined_value(); | 1427 return isolate->factory()->undefined_value(); |
(...skipping 28 matching lines...) Expand all Loading... |
1454 ShouldThrow should_throw) { | 1456 ShouldThrow should_throw) { |
1455 Isolate* isolate = it->isolate(); | 1457 Isolate* isolate = it->isolate(); |
1456 Handle<Object> structure = it->GetAccessors(); | 1458 Handle<Object> structure = it->GetAccessors(); |
1457 Handle<Object> receiver = it->GetReceiver(); | 1459 Handle<Object> receiver = it->GetReceiver(); |
1458 | 1460 |
1459 // We should never get here to initialize a const with the hole value since a | 1461 // We should never get here to initialize a const with the hole value since a |
1460 // const declaration would conflict with the setter. | 1462 // const declaration would conflict with the setter. |
1461 DCHECK(!structure->IsForeign()); | 1463 DCHECK(!structure->IsForeign()); |
1462 | 1464 |
1463 // API style callbacks. | 1465 // API style callbacks. |
| 1466 Handle<JSObject> holder = it->GetHolder<JSObject>(); |
1464 if (structure->IsAccessorInfo()) { | 1467 if (structure->IsAccessorInfo()) { |
1465 Handle<JSObject> holder = it->GetHolder<JSObject>(); | |
1466 Handle<Name> name = it->GetName(); | 1468 Handle<Name> name = it->GetName(); |
1467 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); | 1469 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); |
1468 if (!info->IsCompatibleReceiver(*receiver)) { | 1470 if (!info->IsCompatibleReceiver(*receiver)) { |
1469 isolate->Throw(*isolate->factory()->NewTypeError( | 1471 isolate->Throw(*isolate->factory()->NewTypeError( |
1470 MessageTemplate::kIncompatibleMethodReceiver, name, receiver)); | 1472 MessageTemplate::kIncompatibleMethodReceiver, name, receiver)); |
1471 return Nothing<bool>(); | 1473 return Nothing<bool>(); |
1472 } | 1474 } |
1473 | 1475 |
1474 // The actual type of call_fun is either v8::AccessorNameSetterCallback or | 1476 // The actual type of call_fun is either v8::AccessorNameSetterCallback or |
1475 // i::Accesors::AccessorNameBooleanSetterCallback, depending on whether the | 1477 // i::Accesors::AccessorNameBooleanSetterCallback, depending on whether the |
(...skipping 25 matching lines...) Expand all Loading... |
1501 // (signalling an exception) or a boolean Oddball. | 1503 // (signalling an exception) or a boolean Oddball. |
1502 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); | 1504 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
1503 if (result.is_null()) return Just(true); | 1505 if (result.is_null()) return Just(true); |
1504 DCHECK(result->BooleanValue() || should_throw == DONT_THROW); | 1506 DCHECK(result->BooleanValue() || should_throw == DONT_THROW); |
1505 return Just(result->BooleanValue()); | 1507 return Just(result->BooleanValue()); |
1506 } | 1508 } |
1507 | 1509 |
1508 // Regular accessor. | 1510 // Regular accessor. |
1509 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); | 1511 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); |
1510 if (setter->IsFunctionTemplateInfo()) { | 1512 if (setter->IsFunctionTemplateInfo()) { |
| 1513 SaveContext save(isolate); |
| 1514 isolate->set_context(*holder->GetCreationContext()); |
1511 Handle<Object> argv[] = {value}; | 1515 Handle<Object> argv[] = {value}; |
1512 RETURN_ON_EXCEPTION_VALUE( | 1516 RETURN_ON_EXCEPTION_VALUE( |
1513 isolate, Builtins::InvokeApiFunction( | 1517 isolate, Builtins::InvokeApiFunction( |
1514 isolate, false, Handle<FunctionTemplateInfo>::cast(setter), | 1518 isolate, false, Handle<FunctionTemplateInfo>::cast(setter), |
1515 receiver, arraysize(argv), argv, | 1519 receiver, arraysize(argv), argv, |
1516 isolate->factory()->undefined_value()), | 1520 isolate->factory()->undefined_value()), |
1517 Nothing<bool>()); | 1521 Nothing<bool>()); |
1518 return Just(true); | 1522 return Just(true); |
1519 } else if (setter->IsCallable()) { | 1523 } else if (setter->IsCallable()) { |
1520 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 1524 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
(...skipping 18775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20296 // depend on this. | 20300 // depend on this. |
20297 return DICTIONARY_ELEMENTS; | 20301 return DICTIONARY_ELEMENTS; |
20298 } | 20302 } |
20299 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20303 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20300 return kind; | 20304 return kind; |
20301 } | 20305 } |
20302 } | 20306 } |
20303 | 20307 |
20304 } // namespace internal | 20308 } // namespace internal |
20305 } // namespace v8 | 20309 } // namespace v8 |
OLD | NEW |