Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime.cc

Issue 210953005: Clean up some "GetProperty" methods/functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/objects.cc ('K') | « src/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 621 }
622 622
623 623
624 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateGlobalPrivateSymbol) { 624 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateGlobalPrivateSymbol) {
625 HandleScope scope(isolate); 625 HandleScope scope(isolate);
626 ASSERT(args.length() == 1); 626 ASSERT(args.length() == 1);
627 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 627 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
628 Handle<JSObject> registry = isolate->GetSymbolRegistry(); 628 Handle<JSObject> registry = isolate->GetSymbolRegistry();
629 Handle<String> part = isolate->factory()->private_intern_string(); 629 Handle<String> part = isolate->factory()->private_intern_string();
630 Handle<JSObject> privates = 630 Handle<JSObject> privates =
631 Handle<JSObject>::cast(JSObject::GetProperty(registry, part)); 631 Handle<JSObject>::cast(Object::GetPropertyOrElement(registry, part));
632 Handle<Object> symbol = JSObject::GetProperty(privates, name); 632 Handle<Object> symbol = Object::GetPropertyOrElement(privates, name);
633 if (!symbol->IsSymbol()) { 633 if (!symbol->IsSymbol()) {
634 ASSERT(symbol->IsUndefined()); 634 ASSERT(symbol->IsUndefined());
635 symbol = isolate->factory()->NewPrivateSymbol(); 635 symbol = isolate->factory()->NewPrivateSymbol();
636 Handle<Symbol>::cast(symbol)->set_name(*name); 636 Handle<Symbol>::cast(symbol)->set_name(*name);
637 JSObject::SetProperty(privates, name, symbol, NONE, STRICT); 637 JSObject::SetProperty(privates, name, symbol, NONE, STRICT);
638 } 638 }
639 return *symbol; 639 return *symbol;
640 } 640 }
641 641
642 642
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 ASSERT(!isolate->has_scheduled_exception()); 1897 ASSERT(!isolate->has_scheduled_exception());
1898 AccessorPair* raw_accessors = obj->GetLocalPropertyAccessorPair(*name); 1898 AccessorPair* raw_accessors = obj->GetLocalPropertyAccessorPair(*name);
1899 Handle<AccessorPair> accessors(raw_accessors, isolate); 1899 Handle<AccessorPair> accessors(raw_accessors, isolate);
1900 Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE); 1900 Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE);
1901 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); 1901 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0));
1902 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); 1902 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0));
1903 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(raw_accessors != NULL)); 1903 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(raw_accessors != NULL));
1904 1904
1905 if (raw_accessors == NULL) { 1905 if (raw_accessors == NULL) {
1906 elms->set(WRITABLE_INDEX, heap->ToBoolean((attrs & READ_ONLY) == 0)); 1906 elms->set(WRITABLE_INDEX, heap->ToBoolean((attrs & READ_ONLY) == 0));
1907 // GetProperty does access check. 1907 // Runtime::GetObjectProperty does access check.
1908 Handle<Object> value = GetProperty(isolate, obj, name); 1908 Handle<Object> value = Runtime::GetObjectProperty(isolate, obj, name);
1909 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, value, Handle<Object>::null()); 1909 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, value, Handle<Object>::null());
1910 elms->set(VALUE_INDEX, *value); 1910 elms->set(VALUE_INDEX, *value);
1911 } else { 1911 } else {
1912 // Access checks are performed for both accessors separately. 1912 // Access checks are performed for both accessors separately.
1913 // When they fail, the respective field is not set in the descriptor. 1913 // When they fail, the respective field is not set in the descriptor.
1914 Handle<Object> getter(accessors->GetComponent(ACCESSOR_GETTER), isolate); 1914 Handle<Object> getter(accessors->GetComponent(ACCESSOR_GETTER), isolate);
1915 Handle<Object> setter(accessors->GetComponent(ACCESSOR_SETTER), isolate); 1915 Handle<Object> setter(accessors->GetComponent(ACCESSOR_SETTER), isolate);
1916 1916
1917 if (!getter->IsMap() && CheckPropertyAccess(obj, name, v8::ACCESS_GET)) { 1917 if (!getter->IsMap() && CheckPropertyAccess(obj, name, v8::ACCESS_GET)) {
1918 ASSERT(!isolate->has_scheduled_exception()); 1918 ASSERT(!isolate->has_scheduled_exception());
(...skipping 2997 matching lines...) Expand 10 before | Expand all | Expand 10 after
4916 return isolate->heap()->ToBoolean(JSReceiver::HasElement(object, index)); 4916 return isolate->heap()->ToBoolean(JSReceiver::HasElement(object, index));
4917 } 4917 }
4918 4918
4919 // Convert the key to a name - possibly by calling back into JavaScript. 4919 // Convert the key to a name - possibly by calling back into JavaScript.
4920 Handle<Name> name = ToName(isolate, key); 4920 Handle<Name> name = ToName(isolate, key);
4921 RETURN_IF_EMPTY_HANDLE(isolate, name); 4921 RETURN_IF_EMPTY_HANDLE(isolate, name);
4922 4922
4923 return isolate->heap()->ToBoolean(JSReceiver::HasProperty(object, name)); 4923 return isolate->heap()->ToBoolean(JSReceiver::HasProperty(object, name));
4924 } 4924 }
4925 4925
4926 MaybeObject* Runtime::GetObjectPropertyOrFail(
4927 Isolate* isolate,
4928 Handle<Object> object,
4929 Handle<Object> key) {
4930 CALL_HEAP_FUNCTION_PASS_EXCEPTION(isolate,
4931 GetObjectProperty(isolate, object, key));
4932 }
4933 4926
4934 MaybeObject* Runtime::GetObjectProperty(Isolate* isolate, 4927 Handle<Object> Runtime::GetObjectProperty(Isolate* isolate,
4935 Handle<Object> object, 4928 Handle<Object> object,
4936 Handle<Object> key) { 4929 Handle<Object> key) {
4937 HandleScope scope(isolate);
4938
4939 if (object->IsUndefined() || object->IsNull()) { 4930 if (object->IsUndefined() || object->IsNull()) {
4940 Handle<Object> args[2] = { key, object }; 4931 Handle<Object> args[2] = { key, object };
4941 Handle<Object> error = 4932 isolate->Throw(*isolate->factory()->NewTypeError("non_object_property_load",
4942 isolate->factory()->NewTypeError("non_object_property_load", 4933 HandleVector(args, 2)));
4943 HandleVector(args, 2)); 4934 return Handle<Object>();
4944 return isolate->Throw(*error);
4945 } 4935 }
4946 4936
4947 // Check if the given key is an array index. 4937 // Check if the given key is an array index.
4948 uint32_t index; 4938 uint32_t index;
4949 if (key->ToArrayIndex(&index)) { 4939 if (key->ToArrayIndex(&index)) {
4950 Handle<Object> result = GetElementOrCharAt(isolate, object, index); 4940 return GetElementOrCharAt(isolate, object, index);
4951 RETURN_IF_EMPTY_HANDLE(isolate, result);
4952 return *result;
4953 } 4941 }
4954 4942
4955 // Convert the key to a name - possibly by calling back into JavaScript. 4943 // Convert the key to a name - possibly by calling back into JavaScript.
4956 Handle<Name> name = ToName(isolate, key); 4944 Handle<Name> name = ToName(isolate, key);
4957 RETURN_IF_EMPTY_HANDLE(isolate, name); 4945 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, name, Handle<Object>());
4958 4946
4959 // Check if the name is trivially convertible to an index and get 4947 // Check if the name is trivially convertible to an index and get
4960 // the element if so. 4948 // the element if so.
4961 if (name->AsArrayIndex(&index)) { 4949 if (name->AsArrayIndex(&index)) {
4962 Handle<Object> result = GetElementOrCharAt(isolate, object, index); 4950 return GetElementOrCharAt(isolate, object, index);
4963 RETURN_IF_EMPTY_HANDLE(isolate, result);
4964 return *result;
4965 } else { 4951 } else {
4966 return object->GetProperty(*name); 4952 return Object::GetProperty(object, name);
4967 } 4953 }
4968 } 4954 }
4969 4955
4970 4956
4971 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetProperty) { 4957 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetProperty) {
4972 SealHandleScope shs(isolate); 4958 HandleScope scope(isolate);
4973 ASSERT(args.length() == 2); 4959 ASSERT(args.length() == 2);
4974 4960
4975 Handle<Object> object = args.at<Object>(0); 4961 Handle<Object> object = args.at<Object>(0);
4976 Handle<Object> key = args.at<Object>(1); 4962 Handle<Object> key = args.at<Object>(1);
4977 4963 Handle<Object> result = Runtime::GetObjectProperty(isolate, object, key);
4978 return Runtime::GetObjectProperty(isolate, object, key); 4964 RETURN_IF_EMPTY_HANDLE(isolate, result);
4965 return *result;
4979 } 4966 }
4980 4967
4981 4968
4982 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric. 4969 // KeyedGetProperty is called from KeyedLoadIC::GenerateGeneric.
4983 RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) { 4970 RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) {
4984 SealHandleScope shs(isolate); 4971 SealHandleScope shs(isolate);
4985 ASSERT(args.length() == 2); 4972 ASSERT(args.length() == 2);
4986 4973
4987 // Fast cases for getting named properties of the receiver JSObject 4974 // Fast cases for getting named properties of the receiver JSObject
4988 // itself. 4975 // itself.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
5071 HandleScope scope(isolate); 5058 HandleScope scope(isolate);
5072 Handle<String> str = args.at<String>(0); 5059 Handle<String> str = args.at<String>(0);
5073 int index = args.smi_at(1); 5060 int index = args.smi_at(1);
5074 if (index >= 0 && index < str->length()) { 5061 if (index >= 0 && index < str->length()) {
5075 Handle<Object> result = GetCharAt(str, index); 5062 Handle<Object> result = GetCharAt(str, index);
5076 return *result; 5063 return *result;
5077 } 5064 }
5078 } 5065 }
5079 5066
5080 // Fall back to GetObjectProperty. 5067 // Fall back to GetObjectProperty.
5081 return Runtime::GetObjectProperty(isolate, 5068 HandleScope scope(isolate);
5082 args.at<Object>(0), 5069 Handle<Object> result = Runtime::GetObjectProperty(
5083 args.at<Object>(1)); 5070 isolate, args.at<Object>(0), args.at<Object>(1));
5071 RETURN_IF_EMPTY_HANDLE(isolate, result);
5072 return *result;
5084 } 5073 }
5085 5074
5086 5075
5087 static bool IsValidAccessor(Handle<Object> obj) { 5076 static bool IsValidAccessor(Handle<Object> obj) {
5088 return obj->IsUndefined() || obj->IsSpecFunction() || obj->IsNull(); 5077 return obj->IsUndefined() || obj->IsSpecFunction() || obj->IsNull();
5089 } 5078 }
5090 5079
5091 5080
5092 // Implements part of 8.12.9 DefineOwnProperty. 5081 // Implements part of 8.12.9 DefineOwnProperty.
5093 // There are 3 cases that lead here: 5082 // There are 3 cases that lead here:
(...skipping 6416 matching lines...) Expand 10 before | Expand all | Expand 10 after
11510 Handle<ScopeInfo> scope_info(shared->scope_info()); 11499 Handle<ScopeInfo> scope_info(shared->scope_info());
11511 11500
11512 // Parameters. 11501 // Parameters.
11513 for (int i = 0; i < scope_info->ParameterCount(); ++i) { 11502 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
11514 // Shadowed parameters were not materialized. 11503 // Shadowed parameters were not materialized.
11515 if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; 11504 if (ParameterIsShadowedByContextLocal(scope_info, i)) continue;
11516 11505
11517 ASSERT(!frame->GetParameter(i)->IsTheHole()); 11506 ASSERT(!frame->GetParameter(i)->IsTheHole());
11518 HandleScope scope(isolate); 11507 HandleScope scope(isolate);
11519 Handle<String> name(scope_info->ParameterName(i)); 11508 Handle<String> name(scope_info->ParameterName(i));
11520 Handle<Object> value = GetProperty(isolate, target, name); 11509 Handle<Object> value = Object::GetPropertyOrElement(target, name);
11521 frame->SetParameterValue(i, *value); 11510 frame->SetParameterValue(i, *value);
11522 } 11511 }
11523 11512
11524 // Stack locals. 11513 // Stack locals.
11525 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { 11514 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
11526 if (frame->GetExpression(i)->IsTheHole()) continue; 11515 if (frame->GetExpression(i)->IsTheHole()) continue;
11527 HandleScope scope(isolate); 11516 HandleScope scope(isolate);
11528 Handle<Object> value = GetProperty( 11517 Handle<Object> value = Object::GetPropertyOrElement(
11529 isolate, target, Handle<String>(scope_info->StackLocalName(i))); 11518 target, Handle<String>(scope_info->StackLocalName(i)));
11530 frame->SetExpression(i, *value); 11519 frame->SetExpression(i, *value);
11531 } 11520 }
11532 } 11521 }
11533 11522
11534 11523
11535 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate, 11524 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate,
11536 Handle<JSObject> target, 11525 Handle<JSObject> target,
11537 Handle<JSFunction> function, 11526 Handle<JSFunction> function,
11538 JavaScriptFrame* frame) { 11527 JavaScriptFrame* frame) {
11539 HandleScope scope(isolate); 11528 HandleScope scope(isolate);
(...skipping 23 matching lines...) Expand all
11563 11552
11564 for (int i = 0; i < keys->length(); i++) { 11553 for (int i = 0; i < keys->length(); i++) {
11565 // Names of variables introduced by eval are strings. 11554 // Names of variables introduced by eval are strings.
11566 ASSERT(keys->get(i)->IsString()); 11555 ASSERT(keys->get(i)->IsString());
11567 Handle<String> key(String::cast(keys->get(i))); 11556 Handle<String> key(String::cast(keys->get(i)));
11568 RETURN_IF_EMPTY_HANDLE_VALUE( 11557 RETURN_IF_EMPTY_HANDLE_VALUE(
11569 isolate, 11558 isolate,
11570 Runtime::SetObjectProperty(isolate, 11559 Runtime::SetObjectProperty(isolate,
11571 target, 11560 target,
11572 key, 11561 key,
11573 GetProperty(isolate, ext, key), 11562 Object::GetPropertyOrElement(ext, key),
11574 NONE, 11563 NONE,
11575 SLOPPY), 11564 SLOPPY),
11576 Handle<JSObject>()); 11565 Handle<JSObject>());
11577 } 11566 }
11578 } 11567 }
11579 } 11568 }
11580 11569
11581 return target; 11570 return target;
11582 } 11571 }
11583 11572
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
11713 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); 11702 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw);
11714 if (threw) return Handle<JSObject>(); 11703 if (threw) return Handle<JSObject>();
11715 11704
11716 for (int i = 0; i < keys->length(); i++) { 11705 for (int i = 0; i < keys->length(); i++) {
11717 // Names of variables introduced by eval are strings. 11706 // Names of variables introduced by eval are strings.
11718 ASSERT(keys->get(i)->IsString()); 11707 ASSERT(keys->get(i)->IsString());
11719 Handle<String> key(String::cast(keys->get(i))); 11708 Handle<String> key(String::cast(keys->get(i)));
11720 RETURN_IF_EMPTY_HANDLE_VALUE( 11709 RETURN_IF_EMPTY_HANDLE_VALUE(
11721 isolate, 11710 isolate,
11722 Runtime::SetObjectProperty(isolate, closure_scope, key, 11711 Runtime::SetObjectProperty(isolate, closure_scope, key,
11723 GetProperty(isolate, ext, key), 11712 Object::GetPropertyOrElement(ext, key),
11724 NONE, SLOPPY), 11713 NONE, SLOPPY),
11725 Handle<JSObject>()); 11714 Handle<JSObject>());
11726 } 11715 }
11727 } 11716 }
11728 11717
11729 return closure_scope; 11718 return closure_scope;
11730 } 11719 }
11731 11720
11732 11721
11733 // This method copies structure of MaterializeClosure method above. 11722 // This method copies structure of MaterializeClosure method above.
(...skipping 3370 matching lines...) Expand 10 before | Expand all | Expand 10 after
15104 // Handle last resort GC and make sure to allow future allocations 15093 // Handle last resort GC and make sure to allow future allocations
15105 // to grow the heap without causing GCs (if possible). 15094 // to grow the heap without causing GCs (if possible).
15106 isolate->counters()->gc_last_resort_from_js()->Increment(); 15095 isolate->counters()->gc_last_resort_from_js()->Increment();
15107 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 15096 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
15108 "Runtime::PerformGC"); 15097 "Runtime::PerformGC");
15109 } 15098 }
15110 } 15099 }
15111 15100
15112 15101
15113 } } // namespace v8::internal 15102 } } // namespace v8::internal
OLDNEW
« src/objects.cc ('K') | « src/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698