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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if (structure->IsAccessorInfo()) { | 411 if (structure->IsAccessorInfo()) { |
412 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); | 412 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); |
413 if (!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, | |
422 // so we do not support it for now. | |
423 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | |
424 if (structure->IsDeclaredAccessorInfo()) { | 421 if (structure->IsDeclaredAccessorInfo()) { |
425 return GetDeclaredAccessorProperty( | 422 return GetDeclaredAccessorProperty( |
426 receiver, | 423 receiver, |
427 Handle<DeclaredAccessorInfo>::cast(structure), | 424 Handle<DeclaredAccessorInfo>::cast(structure), |
428 isolate); | 425 isolate); |
429 } | 426 } |
430 | 427 |
431 Handle<ExecutableAccessorInfo> data = | 428 Handle<ExecutableAccessorInfo> data = |
432 Handle<ExecutableAccessorInfo>::cast(structure); | 429 Handle<ExecutableAccessorInfo>::cast(structure); |
433 v8::AccessorGetterCallback call_fun = | 430 v8::AccessorNameGetterCallback call_fun = |
434 v8::ToCData<v8::AccessorGetterCallback>(data->getter()); | 431 v8::ToCData<v8::AccessorNameGetterCallback>(data->getter()); |
435 if (call_fun == NULL) return isolate->factory()->undefined_value(); | 432 if (call_fun == NULL) return isolate->factory()->undefined_value(); |
436 | 433 |
437 Handle<String> key = Handle<String>::cast(name); | |
438 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name)); | 434 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name)); |
439 PropertyCallbackArguments args(isolate, data->data(), *receiver, *holder); | 435 PropertyCallbackArguments args(isolate, data->data(), *receiver, *holder); |
440 v8::Handle<v8::Value> result = | 436 v8::Handle<v8::Value> result = |
441 args.Call(call_fun, v8::Utils::ToLocal(key)); | 437 args.Call(call_fun, v8::Utils::ToLocal(name)); |
442 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 438 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
443 if (result.IsEmpty()) { | 439 if (result.IsEmpty()) { |
444 return isolate->factory()->undefined_value(); | 440 return isolate->factory()->undefined_value(); |
445 } | 441 } |
446 Handle<Object> return_value = v8::Utils::OpenHandle(*result); | 442 Handle<Object> return_value = v8::Utils::OpenHandle(*result); |
447 return_value->VerifyApiCallResultType(); | 443 return_value->VerifyApiCallResultType(); |
448 // Rebox handle before return. | 444 // Rebox handle before return. |
449 return handle(*return_value, isolate); | 445 return handle(*return_value, isolate); |
450 } | 446 } |
451 | 447 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // api style callbacks | 483 // api style callbacks |
488 ExecutableAccessorInfo* info = ExecutableAccessorInfo::cast(*structure); | 484 ExecutableAccessorInfo* info = ExecutableAccessorInfo::cast(*structure); |
489 if (!info->IsCompatibleReceiver(*receiver)) { | 485 if (!info->IsCompatibleReceiver(*receiver)) { |
490 Handle<Object> args[2] = { name, receiver }; | 486 Handle<Object> args[2] = { name, receiver }; |
491 Handle<Object> error = | 487 Handle<Object> error = |
492 isolate->factory()->NewTypeError("incompatible_method_receiver", | 488 isolate->factory()->NewTypeError("incompatible_method_receiver", |
493 HandleVector(args, | 489 HandleVector(args, |
494 ARRAY_SIZE(args))); | 490 ARRAY_SIZE(args))); |
495 return isolate->Throw<Object>(error); | 491 return isolate->Throw<Object>(error); |
496 } | 492 } |
497 // TODO(rossberg): Support symbols in the API. | |
498 if (name->IsSymbol()) return value; | |
499 Object* call_obj = info->setter(); | 493 Object* call_obj = info->setter(); |
500 v8::AccessorSetterCallback call_fun = | 494 v8::AccessorNameSetterCallback call_fun = |
501 v8::ToCData<v8::AccessorSetterCallback>(call_obj); | 495 v8::ToCData<v8::AccessorNameSetterCallback>(call_obj); |
502 if (call_fun == NULL) return value; | 496 if (call_fun == NULL) return value; |
503 Handle<String> key = Handle<String>::cast(name); | |
504 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); | 497 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *name)); |
505 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder); | 498 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder); |
506 args.Call(call_fun, | 499 args.Call(call_fun, |
507 v8::Utils::ToLocal(key), | 500 v8::Utils::ToLocal(name), |
508 v8::Utils::ToLocal(value)); | 501 v8::Utils::ToLocal(value)); |
509 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 502 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
510 return value; | 503 return value; |
511 } | 504 } |
512 | 505 |
513 if (structure->IsAccessorPair()) { | 506 if (structure->IsAccessorPair()) { |
514 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); | 507 Handle<Object> setter(AccessorPair::cast(*structure)->setter(), isolate); |
515 if (setter->IsSpecFunction()) { | 508 if (setter->IsSpecFunction()) { |
516 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 509 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
517 return SetPropertyWithDefinedSetter( | 510 return SetPropertyWithDefinedSetter( |
(...skipping 11760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12278 Handle<Object> structure, | 12271 Handle<Object> structure, |
12279 uint32_t index, | 12272 uint32_t index, |
12280 Handle<Object> holder) { | 12273 Handle<Object> holder) { |
12281 Isolate* isolate = object->GetIsolate(); | 12274 Isolate* isolate = object->GetIsolate(); |
12282 DCHECK(!structure->IsForeign()); | 12275 DCHECK(!structure->IsForeign()); |
12283 // api style callbacks. | 12276 // api style callbacks. |
12284 if (structure->IsExecutableAccessorInfo()) { | 12277 if (structure->IsExecutableAccessorInfo()) { |
12285 Handle<ExecutableAccessorInfo> data = | 12278 Handle<ExecutableAccessorInfo> data = |
12286 Handle<ExecutableAccessorInfo>::cast(structure); | 12279 Handle<ExecutableAccessorInfo>::cast(structure); |
12287 Object* fun_obj = data->getter(); | 12280 Object* fun_obj = data->getter(); |
12288 v8::AccessorGetterCallback call_fun = | 12281 v8::AccessorNameGetterCallback call_fun = |
12289 v8::ToCData<v8::AccessorGetterCallback>(fun_obj); | 12282 v8::ToCData<v8::AccessorNameGetterCallback>(fun_obj); |
12290 if (call_fun == NULL) return isolate->factory()->undefined_value(); | 12283 if (call_fun == NULL) return isolate->factory()->undefined_value(); |
12291 Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder); | 12284 Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder); |
12292 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); | 12285 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); |
12293 Handle<String> key = isolate->factory()->NumberToString(number); | 12286 Handle<String> key = isolate->factory()->NumberToString(number); |
12294 LOG(isolate, ApiNamedPropertyAccess("load", *holder_handle, *key)); | 12287 LOG(isolate, ApiNamedPropertyAccess("load", *holder_handle, *key)); |
12295 PropertyCallbackArguments | 12288 PropertyCallbackArguments |
12296 args(isolate, data->data(), *receiver, *holder_handle); | 12289 args(isolate, data->data(), *receiver, *holder_handle); |
12297 v8::Handle<v8::Value> result = args.Call(call_fun, v8::Utils::ToLocal(key)); | 12290 v8::Handle<v8::Value> result = args.Call(call_fun, v8::Utils::ToLocal(key)); |
12298 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 12291 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
12299 if (result.IsEmpty()) return isolate->factory()->undefined_value(); | 12292 if (result.IsEmpty()) return isolate->factory()->undefined_value(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12336 | 12329 |
12337 // We should never get here to initialize a const with the hole | 12330 // We should never get here to initialize a const with the hole |
12338 // value since a const declaration would conflict with the setter. | 12331 // value since a const declaration would conflict with the setter. |
12339 DCHECK(!value->IsTheHole()); | 12332 DCHECK(!value->IsTheHole()); |
12340 DCHECK(!structure->IsForeign()); | 12333 DCHECK(!structure->IsForeign()); |
12341 if (structure->IsExecutableAccessorInfo()) { | 12334 if (structure->IsExecutableAccessorInfo()) { |
12342 // api style callbacks | 12335 // api style callbacks |
12343 Handle<ExecutableAccessorInfo> data = | 12336 Handle<ExecutableAccessorInfo> data = |
12344 Handle<ExecutableAccessorInfo>::cast(structure); | 12337 Handle<ExecutableAccessorInfo>::cast(structure); |
12345 Object* call_obj = data->setter(); | 12338 Object* call_obj = data->setter(); |
12346 v8::AccessorSetterCallback call_fun = | 12339 v8::AccessorNameSetterCallback call_fun = |
12347 v8::ToCData<v8::AccessorSetterCallback>(call_obj); | 12340 v8::ToCData<v8::AccessorNameSetterCallback>(call_obj); |
12348 if (call_fun == NULL) return value; | 12341 if (call_fun == NULL) return value; |
12349 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); | 12342 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); |
12350 Handle<String> key(isolate->factory()->NumberToString(number)); | 12343 Handle<String> key(isolate->factory()->NumberToString(number)); |
12351 LOG(isolate, ApiNamedPropertyAccess("store", *object, *key)); | 12344 LOG(isolate, ApiNamedPropertyAccess("store", *object, *key)); |
12352 PropertyCallbackArguments | 12345 PropertyCallbackArguments |
12353 args(isolate, data->data(), *object, *holder); | 12346 args(isolate, data->data(), *object, *holder); |
12354 args.Call(call_fun, | 12347 args.Call(call_fun, |
12355 v8::Utils::ToLocal(key), | 12348 v8::Utils::ToLocal(key), |
12356 v8::Utils::ToLocal(value)); | 12349 v8::Utils::ToLocal(value)); |
12357 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 12350 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
(...skipping 4562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16920 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16913 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16921 static const char* error_messages_[] = { | 16914 static const char* error_messages_[] = { |
16922 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16915 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16923 }; | 16916 }; |
16924 #undef ERROR_MESSAGES_TEXTS | 16917 #undef ERROR_MESSAGES_TEXTS |
16925 return error_messages_[reason]; | 16918 return error_messages_[reason]; |
16926 } | 16919 } |
16927 | 16920 |
16928 | 16921 |
16929 } } // namespace v8::internal | 16922 } } // namespace v8::internal |
OLD | NEW |