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::GetPropertyWithForeignCallback( |
Michael Starzinger
2013/10/16 08:21:07
nit: Does this need to be a member method on JSObj
| |
346 Object* structure, | 346 Isolate* isolate, |
347 Name* name) { | 347 Handle<Object> structure, |
348 Handle<Object> receiver) { | |
349 AccessorDescriptor* callback = | |
350 reinterpret_cast<AccessorDescriptor*>( | |
351 Handle<Foreign>::cast(structure)->foreign_address()); | |
352 CALL_HEAP_FUNCTION(isolate, | |
353 (callback->getter)(isolate, *receiver, callback->data), | |
354 Object); | |
355 } | |
356 | |
357 | |
358 Handle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object, | |
359 Handle<Object> receiver, | |
360 Handle<Object> structure, | |
361 Handle<Name> name) { | |
348 Isolate* isolate = name->GetIsolate(); | 362 Isolate* isolate = name->GetIsolate(); |
349 // To accommodate both the old and the new api we switch on the | 363 // To accommodate both the old and the new api we switch on the |
350 // data structure used to store the callbacks. Eventually foreign | 364 // data structure used to store the callbacks. Eventually foreign |
351 // callbacks should be phased out. | 365 // callbacks should be phased out. |
352 if (structure->IsForeign()) { | 366 if (structure->IsForeign()) { |
353 AccessorDescriptor* callback = | 367 Handle<Object> value = GetPropertyWithForeignCallback( |
354 reinterpret_cast<AccessorDescriptor*>( | 368 isolate, structure, receiver); |
355 Foreign::cast(structure)->foreign_address()); | 369 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
356 MaybeObject* value = (callback->getter)(isolate, receiver, callback->data); | |
357 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | |
358 return value; | 370 return value; |
359 } | 371 } |
360 | 372 |
361 // api style callbacks. | 373 // api style callbacks. |
362 if (structure->IsAccessorInfo()) { | 374 if (structure->IsAccessorInfo()) { |
363 if (!AccessorInfo::cast(structure)->IsCompatibleReceiver(receiver)) { | 375 Handle<AccessorInfo> accessor_info = Handle<AccessorInfo>::cast(structure); |
364 Handle<Object> name_handle(name, isolate); | 376 if (!accessor_info->IsCompatibleReceiver(*receiver)) { |
365 Handle<Object> receiver_handle(receiver, isolate); | 377 Handle<Object> args[2] = { name, receiver }; |
366 Handle<Object> args[2] = { name_handle, receiver_handle }; | |
367 Handle<Object> error = | 378 Handle<Object> error = |
368 isolate->factory()->NewTypeError("incompatible_method_receiver", | 379 isolate->factory()->NewTypeError("incompatible_method_receiver", |
369 HandleVector(args, | 380 HandleVector(args, |
370 ARRAY_SIZE(args))); | 381 ARRAY_SIZE(args))); |
371 return isolate->Throw(*error); | 382 isolate->Throw(*error); |
383 return Handle<Object>::null(); | |
372 } | 384 } |
373 // TODO(rossberg): Handling symbols in the API requires changing the API, | 385 // TODO(rossberg): Handling symbols in the API requires changing the API, |
374 // so we do not support it for now. | 386 // so we do not support it for now. |
375 if (name->IsSymbol()) return isolate->heap()->undefined_value(); | 387 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
376 if (structure->IsDeclaredAccessorInfo()) { | 388 if (structure->IsDeclaredAccessorInfo()) { |
377 return GetDeclaredAccessorProperty(receiver, | 389 CALL_HEAP_FUNCTION( |
378 DeclaredAccessorInfo::cast(structure), | 390 isolate, |
379 isolate); | 391 GetDeclaredAccessorProperty(*receiver, |
392 DeclaredAccessorInfo::cast(*structure), | |
393 isolate), | |
394 Object); | |
380 } | 395 } |
381 ExecutableAccessorInfo* data = ExecutableAccessorInfo::cast(structure); | 396 |
382 Object* fun_obj = data->getter(); | 397 Handle<ExecutableAccessorInfo> data = |
398 Handle<ExecutableAccessorInfo>::cast(structure); | |
383 v8::AccessorGetterCallback call_fun = | 399 v8::AccessorGetterCallback call_fun = |
384 v8::ToCData<v8::AccessorGetterCallback>(fun_obj); | 400 v8::ToCData<v8::AccessorGetterCallback>(data->getter()); |
385 if (call_fun == NULL) return isolate->heap()->undefined_value(); | 401 if (call_fun == NULL) return isolate->factory()->undefined_value(); |
402 | |
386 HandleScope scope(isolate); | 403 HandleScope scope(isolate); |
387 JSObject* self = JSObject::cast(receiver); | 404 Handle<JSObject> self = Handle<JSObject>::cast(receiver); |
388 Handle<String> key(String::cast(name)); | 405 Handle<String> key = Handle<String>::cast(name); |
389 LOG(isolate, ApiNamedPropertyAccess("load", self, name)); | 406 LOG(isolate, ApiNamedPropertyAccess("load", *self, *name)); |
390 PropertyCallbackArguments args(isolate, data->data(), self, this); | 407 PropertyCallbackArguments args(isolate, data->data(), *self, *object); |
391 v8::Handle<v8::Value> result = | 408 v8::Handle<v8::Value> result = |
392 args.Call(call_fun, v8::Utils::ToLocal(key)); | 409 args.Call(call_fun, v8::Utils::ToLocal(key)); |
393 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 410 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
394 if (result.IsEmpty()) { | 411 if (result.IsEmpty()) { |
395 return isolate->heap()->undefined_value(); | 412 return isolate->factory()->undefined_value(); |
396 } | 413 } |
397 Object* return_value = *v8::Utils::OpenHandle(*result); | 414 Handle<Object> return_value = v8::Utils::OpenHandle(*result); |
398 return_value->VerifyApiCallResultType(); | 415 return_value->VerifyApiCallResultType(); |
399 return return_value; | 416 return scope.CloseAndEscape(return_value); |
400 } | 417 } |
401 | 418 |
402 // __defineGetter__ callback | 419 // __defineGetter__ callback |
403 if (structure->IsAccessorPair()) { | 420 Handle<Object> getter(Handle<AccessorPair>::cast(structure)->getter(), |
404 Object* getter = AccessorPair::cast(structure)->getter(); | 421 isolate); |
405 if (getter->IsSpecFunction()) { | 422 if (getter->IsSpecFunction()) { |
406 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 423 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
407 return GetPropertyWithDefinedGetter(receiver, JSReceiver::cast(getter)); | 424 CALL_HEAP_FUNCTION( |
408 } | 425 isolate, |
409 // Getter is not a function. | 426 object->GetPropertyWithDefinedGetter(*receiver, |
410 return isolate->heap()->undefined_value(); | 427 JSReceiver::cast(*getter)), |
428 Object); | |
411 } | 429 } |
412 | 430 // Getter is not a function. |
413 UNREACHABLE(); | 431 return isolate->factory()->undefined_value(); |
414 return NULL; | |
415 } | 432 } |
416 | 433 |
417 | 434 |
418 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw, | 435 MaybeObject* JSProxy::GetPropertyWithHandler(Object* receiver_raw, |
419 Name* name_raw) { | 436 Name* name_raw) { |
420 Isolate* isolate = GetIsolate(); | 437 Isolate* isolate = GetIsolate(); |
421 HandleScope scope(isolate); | 438 HandleScope scope(isolate); |
422 Handle<Object> receiver(receiver_raw, isolate); | 439 Handle<Object> receiver(receiver_raw, isolate); |
423 Handle<Object> name(name_raw, isolate); | 440 Handle<Object> name(name_raw, isolate); |
424 | 441 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 | 516 |
500 bool has_pending_exception; | 517 bool has_pending_exception; |
501 Handle<Object> result = Execution::Call( | 518 Handle<Object> result = Execution::Call( |
502 isolate, fun, self, 0, NULL, &has_pending_exception, true); | 519 isolate, fun, self, 0, NULL, &has_pending_exception, true); |
503 // Check for pending exception and return the result. | 520 // Check for pending exception and return the result. |
504 if (has_pending_exception) return Failure::Exception(); | 521 if (has_pending_exception) return Failure::Exception(); |
505 return *result; | 522 return *result; |
506 } | 523 } |
507 | 524 |
508 | 525 |
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 | 526 // Only deal with CALLBACKS and INTERCEPTOR |
523 Handle<Object> JSObject::GetPropertyWithFailedAccessCheck( | 527 Handle<Object> JSObject::GetPropertyWithFailedAccessCheck( |
524 Handle<JSObject> object, | 528 Handle<JSObject> object, |
525 Handle<Object> receiver, | 529 Handle<Object> receiver, |
526 LookupResult* result, | 530 LookupResult* result, |
527 Handle<Name> name, | 531 Handle<Name> name, |
528 PropertyAttributes* attributes) { | 532 PropertyAttributes* attributes) { |
529 Isolate* isolate = name->GetIsolate(); | 533 Isolate* isolate = name->GetIsolate(); |
530 if (result->IsProperty()) { | 534 if (result->IsProperty()) { |
531 switch (result->type()) { | 535 switch (result->type()) { |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 case FIELD: { | 899 case FIELD: { |
896 MaybeObject* maybe_result = result->holder()->FastPropertyAt( | 900 MaybeObject* maybe_result = result->holder()->FastPropertyAt( |
897 result->representation(), | 901 result->representation(), |
898 result->GetFieldIndex().field_index()); | 902 result->GetFieldIndex().field_index()); |
899 if (!maybe_result->To(&value)) return maybe_result; | 903 if (!maybe_result->To(&value)) return maybe_result; |
900 ASSERT(!value->IsTheHole() || result->IsReadOnly()); | 904 ASSERT(!value->IsTheHole() || result->IsReadOnly()); |
901 return value->IsTheHole() ? heap->undefined_value() : value; | 905 return value->IsTheHole() ? heap->undefined_value() : value; |
902 } | 906 } |
903 case CONSTANT: | 907 case CONSTANT: |
904 return result->GetConstant(); | 908 return result->GetConstant(); |
905 case CALLBACKS: | 909 case CALLBACKS: { |
906 return result->holder()->GetPropertyWithCallback( | 910 HandleScope scope(isolate); |
907 receiver, result->GetCallbackObject(), name); | 911 Handle<Object> value = JSObject::GetPropertyWithCallback( |
912 handle(result->holder(), isolate), | |
913 handle(receiver, isolate), | |
914 handle(result->GetCallbackObject(), isolate), | |
915 handle(name, isolate)); | |
916 RETURN_IF_EMPTY_HANDLE(isolate, value); | |
917 return *value; | |
918 } | |
908 case HANDLER: | 919 case HANDLER: |
909 return result->proxy()->GetPropertyWithHandler(receiver, name); | 920 return result->proxy()->GetPropertyWithHandler(receiver, name); |
910 case INTERCEPTOR: { | 921 case INTERCEPTOR: { |
911 HandleScope scope(isolate); | 922 HandleScope scope(isolate); |
912 Handle<Object> value = JSObject::GetPropertyWithInterceptor( | 923 Handle<Object> value = JSObject::GetPropertyWithInterceptor( |
913 handle(result->holder(), isolate), | 924 handle(result->holder(), isolate), |
914 handle(receiver, isolate), | 925 handle(receiver, isolate), |
915 handle(name, isolate), | 926 handle(name, isolate), |
916 attributes); | 927 attributes); |
917 RETURN_IF_EMPTY_HANDLE(isolate, value); | 928 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, | 16285 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16275 static const char* error_messages_[] = { | 16286 static const char* error_messages_[] = { |
16276 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16287 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16277 }; | 16288 }; |
16278 #undef ERROR_MESSAGES_TEXTS | 16289 #undef ERROR_MESSAGES_TEXTS |
16279 return error_messages_[reason]; | 16290 return error_messages_[reason]; |
16280 } | 16291 } |
16281 | 16292 |
16282 | 16293 |
16283 } } // namespace v8::internal | 16294 } } // namespace v8::internal |
OLD | NEW |