OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 | 402 |
403 | 403 |
404 MaybeHandle<Object> Object::GetPropertyWithAccessor(Handle<Object> receiver, | 404 MaybeHandle<Object> Object::GetPropertyWithAccessor(Handle<Object> receiver, |
405 Handle<Name> name, | 405 Handle<Name> name, |
406 Handle<JSObject> holder, | 406 Handle<JSObject> holder, |
407 Handle<Object> structure) { | 407 Handle<Object> structure) { |
408 Isolate* isolate = name->GetIsolate(); | 408 Isolate* isolate = name->GetIsolate(); |
409 ASSERT(!structure->IsForeign()); | 409 ASSERT(!structure->IsForeign()); |
410 // api style callbacks. | 410 // api style callbacks. |
411 if (structure->IsAccessorInfo()) { | 411 if (structure->IsAccessorInfo()) { |
412 Handle<AccessorInfo> accessor_info = Handle<AccessorInfo>::cast(structure); | 412 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); |
413 if (!accessor_info->IsCompatibleReceiver(*receiver)) { | 413 if (!info->IsCompatibleReceiver(*receiver)) { |
414 Handle<Object> args[2] = { name, receiver }; | 414 Handle<Object> args[2] = { name, receiver }; |
415 Handle<Object> error = | 415 Handle<Object> error = |
416 isolate->factory()->NewTypeError("incompatible_method_receiver", | 416 isolate->factory()->NewTypeError("incompatible_method_receiver", |
417 HandleVector(args, | 417 HandleVector(args, |
418 ARRAY_SIZE(args))); | 418 ARRAY_SIZE(args))); |
419 return isolate->Throw<Object>(error); | 419 return isolate->Throw<Object>(error); |
420 } | 420 } |
421 // TODO(rossberg): Handling symbols in the API requires changing the API, | 421 // TODO(rossberg): Handling symbols in the API requires changing the API, |
422 // so we do not support it for now. | 422 // so we do not support it for now. |
423 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | 423 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 if (getter->IsSpecFunction()) { | 455 if (getter->IsSpecFunction()) { |
456 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 456 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
457 return Object::GetPropertyWithDefinedGetter( | 457 return Object::GetPropertyWithDefinedGetter( |
458 receiver, Handle<JSReceiver>::cast(getter)); | 458 receiver, Handle<JSReceiver>::cast(getter)); |
459 } | 459 } |
460 // Getter is not a function. | 460 // Getter is not a function. |
461 return isolate->factory()->undefined_value(); | 461 return isolate->factory()->undefined_value(); |
462 } | 462 } |
463 | 463 |
464 | 464 |
465 bool AccessorInfo::IsCompatibleReceiverType(Isolate* isolate, | |
Igor Sheludko
2014/07/30 10:37:44
What about making it instance method?
| |
466 Handle<AccessorInfo> info, | |
467 Handle<HeapType> type) { | |
468 if (!info->HasExpectedReceiverType()) return true; | |
469 Handle<Map> map = IC::TypeToMap(*type, isolate); | |
470 if (!map->IsJSObjectMap()) return false; | |
471 return FunctionTemplateInfo::cast(info->expected_receiver_type()) | |
472 ->IsTemplateFor(*map); | |
473 } | |
474 | |
475 | |
465 MaybeHandle<Object> Object::SetPropertyWithAccessor( | 476 MaybeHandle<Object> Object::SetPropertyWithAccessor( |
466 Handle<Object> receiver, Handle<Name> name, Handle<Object> value, | 477 Handle<Object> receiver, Handle<Name> name, Handle<Object> value, |
467 Handle<JSObject> holder, Handle<Object> structure, StrictMode strict_mode) { | 478 Handle<JSObject> holder, Handle<Object> structure, StrictMode strict_mode) { |
468 Isolate* isolate = name->GetIsolate(); | 479 Isolate* isolate = name->GetIsolate(); |
469 | 480 |
470 // We should never get here to initialize a const with the hole | 481 // We should never get here to initialize a const with the hole |
471 // value since a const declaration would conflict with the setter. | 482 // value since a const declaration would conflict with the setter. |
472 ASSERT(!structure->IsForeign()); | 483 ASSERT(!structure->IsForeign()); |
473 if (structure->IsExecutableAccessorInfo()) { | 484 if (structure->IsExecutableAccessorInfo()) { |
474 // Don't call executable accessor setters with non-JSObject receivers. | 485 // Don't call executable accessor setters with non-JSObject receivers. |
475 if (!receiver->IsJSObject()) return value; | 486 if (!receiver->IsJSObject()) return value; |
476 // api style callbacks | 487 // api style callbacks |
477 ExecutableAccessorInfo* data = ExecutableAccessorInfo::cast(*structure); | 488 ExecutableAccessorInfo* info = ExecutableAccessorInfo::cast(*structure); |
478 if (!data->IsCompatibleReceiver(*receiver)) { | 489 if (!info->IsCompatibleReceiver(*receiver)) { |
479 Handle<Object> args[2] = { name, receiver }; | 490 Handle<Object> args[2] = { name, receiver }; |
480 Handle<Object> error = | 491 Handle<Object> error = |
481 isolate->factory()->NewTypeError("incompatible_method_receiver", | 492 isolate->factory()->NewTypeError("incompatible_method_receiver", |
482 HandleVector(args, | 493 HandleVector(args, |
483 ARRAY_SIZE(args))); | 494 ARRAY_SIZE(args))); |
484 return isolate->Throw<Object>(error); | 495 return isolate->Throw<Object>(error); |
485 } | 496 } |
486 // TODO(rossberg): Support symbols in the API. | 497 // TODO(rossberg): Support symbols in the API. |
487 if (name->IsSymbol()) return value; | 498 if (name->IsSymbol()) return value; |
488 Object* call_obj = data->setter(); | 499 Object* call_obj = info->setter(); |
489 v8::AccessorSetterCallback call_fun = | 500 v8::AccessorSetterCallback call_fun = |
490 v8::ToCData<v8::AccessorSetterCallback>(call_obj); | 501 v8::ToCData<v8::AccessorSetterCallback>(call_obj); |
491 if (call_fun == NULL) return value; | 502 if (call_fun == NULL) return value; |
492 Handle<String> key = Handle<String>::cast(name); | 503 Handle<String> key = Handle<String>::cast(name); |
493 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); | 504 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); |
494 PropertyCallbackArguments args(isolate, data->data(), *receiver, *holder); | 505 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder); |
495 args.Call(call_fun, | 506 args.Call(call_fun, |
496 v8::Utils::ToLocal(key), | 507 v8::Utils::ToLocal(key), |
497 v8::Utils::ToLocal(value)); | 508 v8::Utils::ToLocal(value)); |
498 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 509 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
499 return value; | 510 return value; |
500 } | 511 } |
501 | 512 |
502 if (structure->IsAccessorPair()) { | 513 if (structure->IsAccessorPair()) { |
503 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); | 514 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); |
504 if (setter->IsSpecFunction()) { | 515 if (setter->IsSpecFunction()) { |
(...skipping 16458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16963 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16974 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16964 static const char* error_messages_[] = { | 16975 static const char* error_messages_[] = { |
16965 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16976 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16966 }; | 16977 }; |
16967 #undef ERROR_MESSAGES_TEXTS | 16978 #undef ERROR_MESSAGES_TEXTS |
16968 return error_messages_[reason]; | 16979 return error_messages_[reason]; |
16969 } | 16980 } |
16970 | 16981 |
16971 | 16982 |
16972 } } // namespace v8::internal | 16983 } } // namespace v8::internal |
OLD | NEW |