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

Side by Side Diff: src/objects.cc

Issue 1148583002: Simplify GetProperty helpers to ease element support (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: More comments Created 5 years, 7 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
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 MaybeHandle<Object> Object::GetProperty(LookupIterator* it) { 129 MaybeHandle<Object> Object::GetProperty(LookupIterator* it) {
130 for (; it->IsFound(); it->Next()) { 130 for (; it->IsFound(); it->Next()) {
131 switch (it->state()) { 131 switch (it->state()) {
132 case LookupIterator::NOT_FOUND: 132 case LookupIterator::NOT_FOUND:
133 case LookupIterator::TRANSITION: 133 case LookupIterator::TRANSITION:
134 UNREACHABLE(); 134 UNREACHABLE();
135 case LookupIterator::JSPROXY: 135 case LookupIterator::JSPROXY:
136 return JSProxy::GetPropertyWithHandler(it->GetHolder<JSProxy>(), 136 return JSProxy::GetPropertyWithHandler(it->GetHolder<JSProxy>(),
137 it->GetReceiver(), it->name()); 137 it->GetReceiver(), it->name());
138 case LookupIterator::INTERCEPTOR: { 138 case LookupIterator::INTERCEPTOR: {
139 MaybeHandle<Object> maybe_result = JSObject::GetPropertyWithInterceptor( 139 MaybeHandle<Object> maybe_result =
140 it->GetHolder<JSObject>(), it->GetReceiver(), it->name()); 140 JSObject::GetPropertyWithInterceptor(it);
141 if (!maybe_result.is_null()) return maybe_result; 141 if (!maybe_result.is_null()) return maybe_result;
142 if (it->isolate()->has_pending_exception()) return maybe_result; 142 if (it->isolate()->has_pending_exception()) return maybe_result;
143 break; 143 break;
144 } 144 }
145 case LookupIterator::ACCESS_CHECK: 145 case LookupIterator::ACCESS_CHECK:
146 if (it->HasAccess()) break; 146 if (it->HasAccess()) break;
147 return JSObject::GetPropertyWithFailedAccessCheck(it); 147 return JSObject::GetPropertyWithFailedAccessCheck(it);
148 case LookupIterator::ACCESSOR: 148 case LookupIterator::ACCESSOR:
149 return GetPropertyWithAccessor(it->GetReceiver(), it->name(), 149 return GetPropertyWithAccessor(it);
150 it->GetHolder<JSObject>(),
151 it->GetAccessors());
152 case LookupIterator::INTEGER_INDEXED_EXOTIC: 150 case LookupIterator::INTEGER_INDEXED_EXOTIC:
153 return it->factory()->undefined_value(); 151 return it->factory()->undefined_value();
154 case LookupIterator::DATA: 152 case LookupIterator::DATA:
155 return it->GetDataValue(); 153 return it->GetDataValue();
156 } 154 }
157 } 155 }
158 return it->factory()->undefined_value(); 156 return it->factory()->undefined_value();
159 } 157 }
160 158
161 159
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 294
297 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 295 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
298 if (name->IsSymbol()) return isolate->factory()->undefined_value(); 296 if (name->IsSymbol()) return isolate->factory()->undefined_value();
299 297
300 Handle<Object> args[] = { receiver, name }; 298 Handle<Object> args[] = { receiver, name };
301 return CallTrap( 299 return CallTrap(
302 proxy, "get", isolate->derived_get_trap(), arraysize(args), args); 300 proxy, "get", isolate->derived_get_trap(), arraysize(args), args);
303 } 301 }
304 302
305 303
306 MaybeHandle<Object> Object::GetPropertyWithAccessor(Handle<Object> receiver, 304 MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) {
307 Handle<Name> name, 305 Isolate* isolate = it->isolate();
308 Handle<JSObject> holder, 306 Handle<Object> structure = it->GetAccessors();
309 Handle<Object> structure) { 307 Handle<Object> receiver = it->GetReceiver();
310 Isolate* isolate = name->GetIsolate(); 308
311 DCHECK(!structure->IsForeign()); 309 DCHECK(!structure->IsForeign());
312 // api style callbacks. 310 // api style callbacks.
313 if (structure->IsAccessorInfo()) { 311 if (structure->IsAccessorInfo()) {
312 Handle<JSObject> holder = it->GetHolder<JSObject>();
313 Handle<Name> name = it->name();
314 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure); 314 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure);
315 if (!info->IsCompatibleReceiver(*receiver)) { 315 if (!info->IsCompatibleReceiver(*receiver)) {
316 THROW_NEW_ERROR(isolate, 316 THROW_NEW_ERROR(isolate,
317 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, 317 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
318 name, receiver), 318 name, receiver),
319 Object); 319 Object);
320 } 320 }
321 321
322 Handle<ExecutableAccessorInfo> data = 322 Handle<ExecutableAccessorInfo> data =
323 Handle<ExecutableAccessorInfo>::cast(structure); 323 Handle<ExecutableAccessorInfo>::cast(structure);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 484 }
485 return false; 485 return false;
486 } 486 }
487 487
488 488
489 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( 489 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck(
490 LookupIterator* it) { 490 LookupIterator* it) {
491 Handle<JSObject> checked = it->GetHolder<JSObject>(); 491 Handle<JSObject> checked = it->GetHolder<JSObject>();
492 while (FindAllCanReadHolder(it)) { 492 while (FindAllCanReadHolder(it)) {
493 if (it->state() == LookupIterator::ACCESSOR) { 493 if (it->state() == LookupIterator::ACCESSOR) {
494 return GetPropertyWithAccessor(it->GetReceiver(), it->name(), 494 return GetPropertyWithAccessor(it);
495 it->GetHolder<JSObject>(),
496 it->GetAccessors());
497 } 495 }
498 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state()); 496 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state());
499 auto receiver = Handle<JSObject>::cast(it->GetReceiver()); 497 auto result = GetPropertyWithInterceptor(it);
500 auto result = GetPropertyWithInterceptor(it->GetHolder<JSObject>(),
501 receiver, it->name());
502 if (it->isolate()->has_scheduled_exception()) break; 498 if (it->isolate()->has_scheduled_exception()) break;
503 if (!result.is_null()) return result; 499 if (!result.is_null()) return result;
504 } 500 }
505 it->isolate()->ReportFailedAccessCheck(checked); 501 it->isolate()->ReportFailedAccessCheck(checked);
506 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object); 502 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object);
507 return it->factory()->undefined_value(); 503 return it->factory()->undefined_value();
508 } 504 }
509 505
510 506
511 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithFailedAccessCheck( 507 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithFailedAccessCheck(
(...skipping 12245 matching lines...) Expand 10 before | Expand all | Expand 10 after
12757 DCHECK(!structure->IsForeign()); 12753 DCHECK(!structure->IsForeign());
12758 // api style callbacks. 12754 // api style callbacks.
12759 if (structure->IsExecutableAccessorInfo()) { 12755 if (structure->IsExecutableAccessorInfo()) {
12760 Handle<ExecutableAccessorInfo> data = 12756 Handle<ExecutableAccessorInfo> data =
12761 Handle<ExecutableAccessorInfo>::cast(structure); 12757 Handle<ExecutableAccessorInfo>::cast(structure);
12762 Object* fun_obj = data->getter(); 12758 Object* fun_obj = data->getter();
12763 v8::AccessorNameGetterCallback call_fun = 12759 v8::AccessorNameGetterCallback call_fun =
12764 v8::ToCData<v8::AccessorNameGetterCallback>(fun_obj); 12760 v8::ToCData<v8::AccessorNameGetterCallback>(fun_obj);
12765 if (call_fun == NULL) return isolate->factory()->undefined_value(); 12761 if (call_fun == NULL) return isolate->factory()->undefined_value();
12766 Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder); 12762 Handle<JSObject> holder_handle = Handle<JSObject>::cast(holder);
12767 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); 12763 Handle<String> key = isolate->factory()->Uint32ToString(index);
12768 Handle<String> key = isolate->factory()->NumberToString(number);
12769 LOG(isolate, ApiNamedPropertyAccess("load", *holder_handle, *key)); 12764 LOG(isolate, ApiNamedPropertyAccess("load", *holder_handle, *key));
12770 PropertyCallbackArguments 12765 PropertyCallbackArguments
12771 args(isolate, data->data(), *receiver, *holder_handle); 12766 args(isolate, data->data(), *receiver, *holder_handle);
12772 v8::Handle<v8::Value> result = args.Call(call_fun, v8::Utils::ToLocal(key)); 12767 v8::Handle<v8::Value> result = args.Call(call_fun, v8::Utils::ToLocal(key));
12773 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 12768 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
12774 if (result.IsEmpty()) return isolate->factory()->undefined_value(); 12769 if (result.IsEmpty()) return isolate->factory()->undefined_value();
12775 Handle<Object> result_internal = v8::Utils::OpenHandle(*result); 12770 Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
12776 result_internal->VerifyApiCallResultType(); 12771 result_internal->VerifyApiCallResultType();
12777 // Rebox handle before return. 12772 // Rebox handle before return.
12778 return handle(*result_internal, isolate); 12773 return handle(*result_internal, isolate);
(...skipping 27 matching lines...) Expand all
12806 DCHECK(!value->IsTheHole()); 12801 DCHECK(!value->IsTheHole());
12807 DCHECK(!structure->IsForeign()); 12802 DCHECK(!structure->IsForeign());
12808 if (structure->IsExecutableAccessorInfo()) { 12803 if (structure->IsExecutableAccessorInfo()) {
12809 // api style callbacks 12804 // api style callbacks
12810 Handle<ExecutableAccessorInfo> data = 12805 Handle<ExecutableAccessorInfo> data =
12811 Handle<ExecutableAccessorInfo>::cast(structure); 12806 Handle<ExecutableAccessorInfo>::cast(structure);
12812 Object* call_obj = data->setter(); 12807 Object* call_obj = data->setter();
12813 v8::AccessorNameSetterCallback call_fun = 12808 v8::AccessorNameSetterCallback call_fun =
12814 v8::ToCData<v8::AccessorNameSetterCallback>(call_obj); 12809 v8::ToCData<v8::AccessorNameSetterCallback>(call_obj);
12815 if (call_fun == NULL) return value; 12810 if (call_fun == NULL) return value;
12816 Handle<Object> number = isolate->factory()->NewNumberFromUint(index); 12811 Handle<String> key(isolate->factory()->Uint32ToString(index));
12817 Handle<String> key(isolate->factory()->NumberToString(number));
12818 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *key)); 12812 LOG(isolate, ApiNamedPropertyAccess("store", *holder, *key));
12819 PropertyCallbackArguments 12813 PropertyCallbackArguments
12820 args(isolate, data->data(), *object, *holder); 12814 args(isolate, data->data(), *object, *holder);
12821 args.Call(call_fun, 12815 args.Call(call_fun,
12822 v8::Utils::ToLocal(key), 12816 v8::Utils::ToLocal(key),
12823 v8::Utils::ToLocal(value)); 12817 v8::Utils::ToLocal(value));
12824 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 12818 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
12825 return value; 12819 return value;
12826 } 12820 }
12827 12821
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
14023 InterceptorInfo* JSObject::GetIndexedInterceptor() { 14017 InterceptorInfo* JSObject::GetIndexedInterceptor() {
14024 DCHECK(map()->has_indexed_interceptor()); 14018 DCHECK(map()->has_indexed_interceptor());
14025 JSFunction* constructor = JSFunction::cast(map()->GetConstructor()); 14019 JSFunction* constructor = JSFunction::cast(map()->GetConstructor());
14026 DCHECK(constructor->shared()->IsApiFunction()); 14020 DCHECK(constructor->shared()->IsApiFunction());
14027 Object* result = 14021 Object* result =
14028 constructor->shared()->get_api_func_data()->indexed_property_handler(); 14022 constructor->shared()->get_api_func_data()->indexed_property_handler();
14029 return InterceptorInfo::cast(result); 14023 return InterceptorInfo::cast(result);
14030 } 14024 }
14031 14025
14032 14026
14033 MaybeHandle<Object> JSObject::GetPropertyWithInterceptor( 14027 MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(LookupIterator* it) {
14034 Handle<JSObject> holder, 14028 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state());
14035 Handle<Object> receiver, 14029 Isolate* isolate = it->isolate();
14036 Handle<Name> name) { 14030 Handle<InterceptorInfo> interceptor = it->GetInterceptor();
14037 Isolate* isolate = holder->GetIsolate(); 14031 if (interceptor->getter()->IsUndefined()) return MaybeHandle<Object>();
14038 14032
14039 Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor(), isolate); 14033 Handle<Name> name = it->name();
14040 if (interceptor->getter()->IsUndefined()) return MaybeHandle<Object>(); 14034 Handle<JSObject> holder = it->GetHolder<JSObject>();
14041 14035
14042 if (name->IsSymbol() && !interceptor->can_intercept_symbols()) { 14036 if (name->IsSymbol() && !interceptor->can_intercept_symbols()) {
14043 return MaybeHandle<Object>(); 14037 return MaybeHandle<Object>();
14044 } 14038 }
14045 14039
14046 v8::GenericNamedPropertyGetterCallback getter = 14040 v8::GenericNamedPropertyGetterCallback getter =
14047 v8::ToCData<v8::GenericNamedPropertyGetterCallback>( 14041 v8::ToCData<v8::GenericNamedPropertyGetterCallback>(
14048 interceptor->getter()); 14042 interceptor->getter());
14049 LOG(isolate, 14043 LOG(isolate,
14050 ApiNamedPropertyAccess("interceptor-named-get", *holder, *name)); 14044 ApiNamedPropertyAccess("interceptor-named-get", *holder, *name));
14051 PropertyCallbackArguments 14045 PropertyCallbackArguments args(isolate, interceptor->data(),
14052 args(isolate, interceptor->data(), *receiver, *holder); 14046 *it->GetReceiver(), *holder);
14053 v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name)); 14047 v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name));
14054 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 14048 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
14055 if (result.IsEmpty()) return MaybeHandle<Object>(); 14049 if (result.IsEmpty()) return MaybeHandle<Object>();
14056 14050
14057 Handle<Object> result_internal = v8::Utils::OpenHandle(*result); 14051 Handle<Object> result_internal = v8::Utils::OpenHandle(*result);
14058 result_internal->VerifyApiCallResultType(); 14052 result_internal->VerifyApiCallResultType();
14059 // Rebox handle before return 14053 // Rebox handle before return
14060 return handle(*result_internal, isolate); 14054 return handle(*result_internal, isolate);
14061 } 14055 }
14062 14056
(...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after
17297 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell, 17291 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell,
17298 Handle<Object> new_value) { 17292 Handle<Object> new_value) {
17299 if (cell->value() != *new_value) { 17293 if (cell->value() != *new_value) {
17300 cell->set_value(*new_value); 17294 cell->set_value(*new_value);
17301 Isolate* isolate = cell->GetIsolate(); 17295 Isolate* isolate = cell->GetIsolate();
17302 cell->dependent_code()->DeoptimizeDependentCodeGroup( 17296 cell->dependent_code()->DeoptimizeDependentCodeGroup(
17303 isolate, DependentCode::kPropertyCellChangedGroup); 17297 isolate, DependentCode::kPropertyCellChangedGroup);
17304 } 17298 }
17305 } 17299 }
17306 } } // namespace v8::internal 17300 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698