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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 // If the constructor is not present, return "Object". | 2111 // If the constructor is not present, return "Object". |
2112 return GetHeap()->Object_string(); | 2112 return GetHeap()->Object_string(); |
2113 } | 2113 } |
2114 | 2114 |
2115 | 2115 |
2116 String* JSReceiver::constructor_name() { | 2116 String* JSReceiver::constructor_name() { |
2117 return map()->constructor_name(); | 2117 return map()->constructor_name(); |
2118 } | 2118 } |
2119 | 2119 |
2120 | 2120 |
| 2121 Context* JSReceiver::GetCreationContext() { |
| 2122 Object* constructor = map()->GetConstructor(); |
| 2123 JSFunction* function; |
| 2124 if (!constructor->IsJSFunction()) { |
| 2125 // Functions have null as a constructor, |
| 2126 // but any JSFunction knows its context immediately. |
| 2127 function = JSFunction::cast(this); |
| 2128 } else { |
| 2129 function = JSFunction::cast(constructor); |
| 2130 } |
| 2131 |
| 2132 return function->context()->native_context(); |
| 2133 } |
| 2134 |
| 2135 |
2121 static Handle<Object> WrapType(Handle<HeapType> type) { | 2136 static Handle<Object> WrapType(Handle<HeapType> type) { |
2122 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map()); | 2137 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map()); |
2123 return type; | 2138 return type; |
2124 } | 2139 } |
2125 | 2140 |
2126 | 2141 |
2127 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, | 2142 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, |
2128 Handle<Name> name, | 2143 Handle<Name> name, |
2129 Handle<HeapType> type, | 2144 Handle<HeapType> type, |
2130 PropertyAttributes attributes, | 2145 PropertyAttributes attributes, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 } else { | 2230 } else { |
2216 Handle<NameDictionary> dict(object->property_dictionary()); | 2231 Handle<NameDictionary> dict(object->property_dictionary()); |
2217 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); | 2232 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); |
2218 Handle<NameDictionary> result = | 2233 Handle<NameDictionary> result = |
2219 NameDictionary::Add(dict, name, value, details); | 2234 NameDictionary::Add(dict, name, value, details); |
2220 if (*dict != *result) object->set_properties(*result); | 2235 if (*dict != *result) object->set_properties(*result); |
2221 } | 2236 } |
2222 } | 2237 } |
2223 | 2238 |
2224 | 2239 |
2225 Context* JSObject::GetCreationContext() { | |
2226 Object* constructor = this->map()->GetConstructor(); | |
2227 JSFunction* function; | |
2228 if (!constructor->IsJSFunction()) { | |
2229 // Functions have null as a constructor, | |
2230 // but any JSFunction knows its context immediately. | |
2231 function = JSFunction::cast(this); | |
2232 } else { | |
2233 function = JSFunction::cast(constructor); | |
2234 } | |
2235 | |
2236 return function->context()->native_context(); | |
2237 } | |
2238 | |
2239 | |
2240 MaybeHandle<Object> JSObject::EnqueueChangeRecord(Handle<JSObject> object, | 2240 MaybeHandle<Object> JSObject::EnqueueChangeRecord(Handle<JSObject> object, |
2241 const char* type_str, | 2241 const char* type_str, |
2242 Handle<Name> name, | 2242 Handle<Name> name, |
2243 Handle<Object> old_value) { | 2243 Handle<Object> old_value) { |
2244 DCHECK(!object->IsJSGlobalProxy()); | 2244 DCHECK(!object->IsJSGlobalProxy()); |
2245 DCHECK(!object->IsJSGlobalObject()); | 2245 DCHECK(!object->IsJSGlobalObject()); |
2246 Isolate* isolate = object->GetIsolate(); | 2246 Isolate* isolate = object->GetIsolate(); |
2247 HandleScope scope(isolate); | 2247 HandleScope scope(isolate); |
2248 Handle<String> type = isolate->factory()->InternalizeUtf8String(type_str); | 2248 Handle<String> type = isolate->factory()->InternalizeUtf8String(type_str); |
2249 Handle<Object> args[] = { type, object, name, old_value }; | 2249 Handle<Object> args[] = { type, object, name, old_value }; |
(...skipping 12452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14702 v8::Local<v8::Object> result; | 14702 v8::Local<v8::Object> result; |
14703 if (!interceptor->enumerator()->IsUndefined()) { | 14703 if (!interceptor->enumerator()->IsUndefined()) { |
14704 v8::GenericNamedPropertyEnumeratorCallback enum_fun = | 14704 v8::GenericNamedPropertyEnumeratorCallback enum_fun = |
14705 v8::ToCData<v8::GenericNamedPropertyEnumeratorCallback>( | 14705 v8::ToCData<v8::GenericNamedPropertyEnumeratorCallback>( |
14706 interceptor->enumerator()); | 14706 interceptor->enumerator()); |
14707 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); | 14707 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); |
14708 result = args.Call(enum_fun); | 14708 result = args.Call(enum_fun); |
14709 } | 14709 } |
14710 if (result.IsEmpty()) return MaybeHandle<JSObject>(); | 14710 if (result.IsEmpty()) return MaybeHandle<JSObject>(); |
14711 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || | 14711 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || |
14712 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); | 14712 (v8::Utils::OpenHandle(*result)->IsJSObject() && |
| 14713 Handle<JSObject>::cast(v8::Utils::OpenHandle(*result)) |
| 14714 ->HasSloppyArgumentsElements())); |
14713 // Rebox before returning. | 14715 // Rebox before returning. |
14714 return handle(*v8::Utils::OpenHandle(*result), isolate); | 14716 return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); |
14715 } | 14717 } |
14716 | 14718 |
14717 | 14719 |
14718 // Compute the element keys from the interceptor. | 14720 // Compute the element keys from the interceptor. |
14719 MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor( | 14721 MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor( |
14720 Handle<JSObject> object, Handle<JSReceiver> receiver) { | 14722 Handle<JSObject> object, Handle<JSReceiver> receiver) { |
14721 Isolate* isolate = receiver->GetIsolate(); | 14723 Isolate* isolate = receiver->GetIsolate(); |
14722 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); | 14724 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); |
14723 PropertyCallbackArguments | 14725 PropertyCallbackArguments |
14724 args(isolate, interceptor->data(), *receiver, *object); | 14726 args(isolate, interceptor->data(), *receiver, *object); |
14725 v8::Local<v8::Object> result; | 14727 v8::Local<v8::Object> result; |
14726 if (!interceptor->enumerator()->IsUndefined()) { | 14728 if (!interceptor->enumerator()->IsUndefined()) { |
14727 v8::IndexedPropertyEnumeratorCallback enum_fun = | 14729 v8::IndexedPropertyEnumeratorCallback enum_fun = |
14728 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>( | 14730 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>( |
14729 interceptor->enumerator()); | 14731 interceptor->enumerator()); |
14730 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); | 14732 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); |
14731 result = args.Call(enum_fun); | 14733 result = args.Call(enum_fun); |
14732 } | 14734 } |
14733 if (result.IsEmpty()) return MaybeHandle<JSObject>(); | 14735 if (result.IsEmpty()) return MaybeHandle<JSObject>(); |
14734 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || | 14736 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || |
14735 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); | 14737 (v8::Utils::OpenHandle(*result)->IsJSObject() && |
| 14738 Handle<JSObject>::cast(v8::Utils::OpenHandle(*result)) |
| 14739 ->HasSloppyArgumentsElements())); |
14736 // Rebox before returning. | 14740 // Rebox before returning. |
14737 return handle(*v8::Utils::OpenHandle(*result), isolate); | 14741 return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); |
14738 } | 14742 } |
14739 | 14743 |
14740 | 14744 |
14741 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, | 14745 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, |
14742 Handle<Name> name) { | 14746 Handle<Name> name) { |
14743 LookupIterator it = LookupIterator::PropertyOrElement( | 14747 LookupIterator it = LookupIterator::PropertyOrElement( |
14744 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 14748 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
14745 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); | 14749 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); |
14746 if (!maybe_result.IsJust()) return Nothing<bool>(); | 14750 if (!maybe_result.IsJust()) return Nothing<bool>(); |
14747 return Just(it.IsFound()); | 14751 return Just(it.IsFound()); |
(...skipping 3167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17915 if (cell->value() != *new_value) { | 17919 if (cell->value() != *new_value) { |
17916 cell->set_value(*new_value); | 17920 cell->set_value(*new_value); |
17917 Isolate* isolate = cell->GetIsolate(); | 17921 Isolate* isolate = cell->GetIsolate(); |
17918 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17922 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
17919 isolate, DependentCode::kPropertyCellChangedGroup); | 17923 isolate, DependentCode::kPropertyCellChangedGroup); |
17920 } | 17924 } |
17921 } | 17925 } |
17922 | 17926 |
17923 } // namespace internal | 17927 } // namespace internal |
17924 } // namespace v8 | 17928 } // namespace v8 |
OLD | NEW |