| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return GetPrimitiveValue(data->primitive_value_descriptor, | 335 return GetPrimitiveValue(data->primitive_value_descriptor, |
| 336 current, | 336 current, |
| 337 isolate->heap()); | 337 isolate->heap()); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 UNREACHABLE(); | 340 UNREACHABLE(); |
| 341 return NULL; | 341 return NULL; |
| 342 } | 342 } |
| 343 | 343 |
| 344 | 344 |
| 345 MaybeObject* JSObject::GetPropertyWithCallback(Object* receiver, | 345 Handle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object, |
| 346 Object* structure, | 346 Handle<Object> receiver, |
| 347 Name* name) { | 347 Handle<Object> structure, |
| 348 Handle<Name> name) { |
| 348 Isolate* isolate = name->GetIsolate(); | 349 Isolate* isolate = name->GetIsolate(); |
| 349 // To accommodate both the old and the new api we switch on the | 350 // To accommodate both the old and the new api we switch on the |
| 350 // data structure used to store the callbacks. Eventually foreign | 351 // data structure used to store the callbacks. Eventually foreign |
| 351 // callbacks should be phased out. | 352 // callbacks should be phased out. |
| 352 if (structure->IsForeign()) { | 353 if (structure->IsForeign()) { |
| 353 AccessorDescriptor* callback = | 354 AccessorDescriptor* callback = |
| 354 reinterpret_cast<AccessorDescriptor*>( | 355 reinterpret_cast<AccessorDescriptor*>( |
| 355 Foreign::cast(structure)->foreign_address()); | 356 Handle<Foreign>::cast(structure)->foreign_address()); |
| 356 MaybeObject* value = (callback->getter)(isolate, receiver, callback->data); | 357 CALL_HEAP_FUNCTION(isolate, |
| 357 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 358 (callback->getter)(isolate, *receiver, callback->data), |
| 358 return value; | 359 Object); |
| 359 } | 360 } |
| 360 | 361 |
| 361 // api style callbacks. | 362 // api style callbacks. |
| 362 if (structure->IsAccessorInfo()) { | 363 if (structure->IsAccessorInfo()) { |
| 363 if (!AccessorInfo::cast(structure)->IsCompatibleReceiver(receiver)) { | 364 Handle<AccessorInfo> accessor_info = Handle<AccessorInfo>::cast(structure); |
| 364 Handle<Object> name_handle(name, isolate); | 365 if (!accessor_info->IsCompatibleReceiver(*receiver)) { |
| 365 Handle<Object> receiver_handle(receiver, isolate); | 366 Handle<Object> args[2] = { name, receiver }; |
| 366 Handle<Object> args[2] = { name_handle, receiver_handle }; | |
| 367 Handle<Object> error = | 367 Handle<Object> error = |
| 368 isolate->factory()->NewTypeError("incompatible_method_receiver", | 368 isolate->factory()->NewTypeError("incompatible_method_receiver", |
| 369 HandleVector(args, | 369 HandleVector(args, |
| 370 ARRAY_SIZE(args))); | 370 ARRAY_SIZE(args))); |
| 371 return isolate->Throw(*error); | 371 isolate->Throw(*error); |
| 372 return Handle<Object>::null(); |
| 372 } | 373 } |
| 373 // TODO(rossberg): Handling symbols in the API requires changing the API, | 374 // TODO(rossberg): Handling symbols in the API requires changing the API, |
| 374 // so we do not support it for now. | 375 // so we do not support it for now. |
| 375 if (name->IsSymbol()) return isolate->heap()->undefined_value(); | 376 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
| 376 if (structure->IsDeclaredAccessorInfo()) { | 377 if (structure->IsDeclaredAccessorInfo()) { |
| 377 return GetDeclaredAccessorProperty(receiver, | 378 CALL_HEAP_FUNCTION( |
| 378 DeclaredAccessorInfo::cast(structure), | 379 isolate, |
| 379 isolate); | 380 GetDeclaredAccessorProperty(*receiver, |
| 381 DeclaredAccessorInfo::cast(*structure), |
| 382 isolate), |
| 383 Object); |
| 380 } | 384 } |
| 381 ExecutableAccessorInfo* data = ExecutableAccessorInfo::cast(structure); | 385 |
| 382 Object* fun_obj = data->getter(); | 386 Handle<ExecutableAccessorInfo> data = |
| 387 Handle<ExecutableAccessorInfo>::cast(structure); |
| 383 v8::AccessorGetterCallback call_fun = | 388 v8::AccessorGetterCallback call_fun = |
| 384 v8::ToCData<v8::AccessorGetterCallback>(fun_obj); | 389 v8::ToCData<v8::AccessorGetterCallback>(data->getter()); |
| 385 if (call_fun == NULL) return isolate->heap()->undefined_value(); | 390 if (call_fun == NULL) return isolate->factory()->undefined_value(); |
| 391 |
| 386 HandleScope scope(isolate); | 392 HandleScope scope(isolate); |
| 387 JSObject* self = JSObject::cast(receiver); | 393 Handle<JSObject> self = Handle<JSObject>::cast(receiver); |
| 388 Handle<String> key(String::cast(name)); | 394 Handle<String> key = Handle<String>::cast(name); |
| 389 LOG(isolate, ApiNamedPropertyAccess("load", self, name)); | 395 LOG(isolate, ApiNamedPropertyAccess("load", *self, *name)); |
| 390 PropertyCallbackArguments args(isolate, data->data(), self, this); | 396 PropertyCallbackArguments args(isolate, data->data(), *self, *object); |
| 391 v8::Handle<v8::Value> result = | 397 v8::Handle<v8::Value> result = |
| 392 args.Call(call_fun, v8::Utils::ToLocal(key)); | 398 args.Call(call_fun, v8::Utils::ToLocal(key)); |
| 393 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 399 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| 394 if (result.IsEmpty()) { | 400 if (result.IsEmpty()) { |
| 395 return isolate->heap()->undefined_value(); | 401 return isolate->factory()->undefined_value(); |
| 396 } | 402 } |
| 397 Object* return_value = *v8::Utils::OpenHandle(*result); | 403 Handle<Object> return_value = v8::Utils::OpenHandle(*result); |
| 398 return_value->VerifyApiCallResultType(); | 404 return_value->VerifyApiCallResultType(); |
| 399 return return_value; | 405 return scope.CloseAndEscape(return_value); |
| 400 } | 406 } |
| 401 | 407 |
| 402 // __defineGetter__ callback | 408 // __defineGetter__ callback |
| 403 if (structure->IsAccessorPair()) { | 409 Handle<Object> getter(Handle<AccessorPair>::cast(structure)->getter(), |
| 404 Object* getter = AccessorPair::cast(structure)->getter(); | 410 isolate); |
| 405 if (getter->IsSpecFunction()) { | 411 if (getter->IsSpecFunction()) { |
| 406 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 412 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
| 407 return GetPropertyWithDefinedGetter(receiver, JSReceiver::cast(getter)); | 413 CALL_HEAP_FUNCTION( |
| 408 } | 414 isolate, |
| 409 // Getter is not a function. | 415 object->GetPropertyWithDefinedGetter(*receiver, |
| 410 return isolate->heap()->undefined_value(); | 416 JSReceiver::cast(*getter)), |
| 417 Object); |
| 411 } | 418 } |
| 412 | 419 // Getter is not a function. |
| 413 UNREACHABLE(); | 420 return isolate->factory()->undefined_value(); |
| 414 return NULL; | |
| 415 } | 421 } |
| 416 | 422 |
| 417 | 423 |
| 418 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw, | 424 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw, |
| 419 Name* name_raw) { | 425 Name* name_raw) { |
| 420 Isolate* isolate = GetIsolate(); | 426 Isolate* isolate = GetIsolate(); |
| 421 HandleScope scope(isolate); | 427 HandleScope scope(isolate); |
| 422 Handle<Object> receiver(receiver_raw, isolate); | 428 Handle<Object> receiver(receiver_raw, isolate); |
| 423 Handle<Object> name(name_raw, isolate); | 429 Handle<Object> name(name_raw, isolate); |
| 424 | 430 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 505 |
| 500 bool has_pending_exception; | 506 bool has_pending_exception; |
| 501 Handle<Object> result = Execution::Call( | 507 Handle<Object> result = Execution::Call( |
| 502 isolate, fun, self, 0, NULL, &has_pending_exception, true); | 508 isolate, fun, self, 0, NULL, &has_pending_exception, true); |
| 503 // Check for pending exception and return the result. | 509 // Check for pending exception and return the result. |
| 504 if (has_pending_exception) return Failure::Exception(); | 510 if (has_pending_exception) return Failure::Exception(); |
| 505 return *result; | 511 return *result; |
| 506 } | 512 } |
| 507 | 513 |
| 508 | 514 |
| 509 // TODO(yangguo): this should eventually replace the non-handlified version. | |
| 510 Handle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object, | |
| 511 Handle<Object> receiver, | |
| 512 Handle<Object> structure, | |
| 513 Handle<Name> name) { | |
| 514 CALL_HEAP_FUNCTION(object->GetIsolate(), | |
| 515 object->GetPropertyWithCallback(*receiver, | |
| 516 *structure, | |
| 517 *name), | |
| 518 Object); | |
| 519 } | |
| 520 | |
| 521 | |
| 522 // Only deal with CALLBACKS and INTERCEPTOR | 515 // Only deal with CALLBACKS and INTERCEPTOR |
| 523 Handle<Object> JSObject::GetPropertyWithFailedAccessCheck( | 516 Handle<Object> JSObject::GetPropertyWithFailedAccessCheck( |
| 524 Handle<JSObject> object, | 517 Handle<JSObject> object, |
| 525 Handle<Object> receiver, | 518 Handle<Object> receiver, |
| 526 LookupResult* result, | 519 LookupResult* result, |
| 527 Handle<Name> name, | 520 Handle<Name> name, |
| 528 PropertyAttributes* attributes) { | 521 PropertyAttributes* attributes) { |
| 529 Isolate* isolate = name->GetIsolate(); | 522 Isolate* isolate = name->GetIsolate(); |
| 530 if (result->IsProperty()) { | 523 if (result->IsProperty()) { |
| 531 switch (result->type()) { | 524 switch (result->type()) { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 case FIELD: { | 888 case FIELD: { |
| 896 MaybeObject* maybe_result = result->holder()->FastPropertyAt( | 889 MaybeObject* maybe_result = result->holder()->FastPropertyAt( |
| 897 result->representation(), | 890 result->representation(), |
| 898 result->GetFieldIndex().field_index()); | 891 result->GetFieldIndex().field_index()); |
| 899 if (!maybe_result->To(&value)) return maybe_result; | 892 if (!maybe_result->To(&value)) return maybe_result; |
| 900 ASSERT(!value->IsTheHole() || result->IsReadOnly()); | 893 ASSERT(!value->IsTheHole() || result->IsReadOnly()); |
| 901 return value->IsTheHole() ? heap->undefined_value() : value; | 894 return value->IsTheHole() ? heap->undefined_value() : value; |
| 902 } | 895 } |
| 903 case CONSTANT: | 896 case CONSTANT: |
| 904 return result->GetConstant(); | 897 return result->GetConstant(); |
| 905 case CALLBACKS: | 898 case CALLBACKS: { |
| 906 return result->holder()->GetPropertyWithCallback( | 899 HandleScope scope(isolate); |
| 907 receiver, result->GetCallbackObject(), name); | 900 Handle<Object> value = JSObject::GetPropertyWithCallback( |
| 901 handle(result->holder(), isolate), |
| 902 handle(receiver, isolate), |
| 903 handle(result->GetCallbackObject(), isolate), |
| 904 handle(name, isolate)); |
| 905 RETURN_IF_EMPTY_HANDLE(isolate, value); |
| 906 return *value; |
| 907 } |
| 908 case HANDLER: | 908 case HANDLER: |
| 909 return result->proxy()->GetPropertyWithHandler(receiver, name); | 909 return result->proxy()->GetPropertyWithHandler(receiver, name); |
| 910 case INTERCEPTOR: { | 910 case INTERCEPTOR: { |
| 911 HandleScope scope(isolate); | 911 HandleScope scope(isolate); |
| 912 Handle<Object> value = JSObject::GetPropertyWithInterceptor( | 912 Handle<Object> value = JSObject::GetPropertyWithInterceptor( |
| 913 handle(result->holder(), isolate), | 913 handle(result->holder(), isolate), |
| 914 handle(receiver, isolate), | 914 handle(receiver, isolate), |
| 915 handle(name, isolate), | 915 handle(name, isolate), |
| 916 attributes); | 916 attributes); |
| 917 RETURN_IF_EMPTY_HANDLE(isolate, value); | 917 RETURN_IF_EMPTY_HANDLE(isolate, value); |
| (...skipping 15356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16274 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16274 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16275 static const char* error_messages_[] = { | 16275 static const char* error_messages_[] = { |
| 16276 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16276 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16277 }; | 16277 }; |
| 16278 #undef ERROR_MESSAGES_TEXTS | 16278 #undef ERROR_MESSAGES_TEXTS |
| 16279 return error_messages_[reason]; | 16279 return error_messages_[reason]; |
| 16280 } | 16280 } |
| 16281 | 16281 |
| 16282 | 16282 |
| 16283 } } // namespace v8::internal | 16283 } } // namespace v8::internal |
| OLD | NEW |