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 2149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 // If the constructor is not present, return "Object". | 2160 // If the constructor is not present, return "Object". |
2161 return GetHeap()->Object_string(); | 2161 return GetHeap()->Object_string(); |
2162 } | 2162 } |
2163 | 2163 |
2164 | 2164 |
2165 String* JSReceiver::constructor_name() { | 2165 String* JSReceiver::constructor_name() { |
2166 return map()->constructor_name(); | 2166 return map()->constructor_name(); |
2167 } | 2167 } |
2168 | 2168 |
2169 | 2169 |
| 2170 Context* JSReceiver::GetCreationContext() { |
| 2171 Object* constructor = map()->GetConstructor(); |
| 2172 JSFunction* function; |
| 2173 if (!constructor->IsJSFunction()) { |
| 2174 // Functions have null as a constructor, |
| 2175 // but any JSFunction knows its context immediately. |
| 2176 function = JSFunction::cast(this); |
| 2177 } else { |
| 2178 function = JSFunction::cast(constructor); |
| 2179 } |
| 2180 |
| 2181 return function->context()->native_context(); |
| 2182 } |
| 2183 |
| 2184 |
2170 static Handle<Object> WrapType(Handle<HeapType> type) { | 2185 static Handle<Object> WrapType(Handle<HeapType> type) { |
2171 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map()); | 2186 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()->Map()); |
2172 return type; | 2187 return type; |
2173 } | 2188 } |
2174 | 2189 |
2175 | 2190 |
2176 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, | 2191 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, |
2177 Handle<Name> name, | 2192 Handle<Name> name, |
2178 Handle<HeapType> type, | 2193 Handle<HeapType> type, |
2179 PropertyAttributes attributes, | 2194 PropertyAttributes attributes, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2264 } else { | 2279 } else { |
2265 Handle<NameDictionary> dict(object->property_dictionary()); | 2280 Handle<NameDictionary> dict(object->property_dictionary()); |
2266 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); | 2281 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); |
2267 Handle<NameDictionary> result = | 2282 Handle<NameDictionary> result = |
2268 NameDictionary::Add(dict, name, value, details); | 2283 NameDictionary::Add(dict, name, value, details); |
2269 if (*dict != *result) object->set_properties(*result); | 2284 if (*dict != *result) object->set_properties(*result); |
2270 } | 2285 } |
2271 } | 2286 } |
2272 | 2287 |
2273 | 2288 |
2274 Context* JSObject::GetCreationContext() { | |
2275 Object* constructor = this->map()->GetConstructor(); | |
2276 JSFunction* function; | |
2277 if (!constructor->IsJSFunction()) { | |
2278 // Functions have null as a constructor, | |
2279 // but any JSFunction knows its context immediately. | |
2280 function = JSFunction::cast(this); | |
2281 } else { | |
2282 function = JSFunction::cast(constructor); | |
2283 } | |
2284 | |
2285 return function->context()->native_context(); | |
2286 } | |
2287 | |
2288 | |
2289 MaybeHandle<Object> JSObject::EnqueueChangeRecord(Handle<JSObject> object, | 2289 MaybeHandle<Object> JSObject::EnqueueChangeRecord(Handle<JSObject> object, |
2290 const char* type_str, | 2290 const char* type_str, |
2291 Handle<Name> name, | 2291 Handle<Name> name, |
2292 Handle<Object> old_value) { | 2292 Handle<Object> old_value) { |
2293 DCHECK(!object->IsJSGlobalProxy()); | 2293 DCHECK(!object->IsJSGlobalProxy()); |
2294 DCHECK(!object->IsJSGlobalObject()); | 2294 DCHECK(!object->IsJSGlobalObject()); |
2295 Isolate* isolate = object->GetIsolate(); | 2295 Isolate* isolate = object->GetIsolate(); |
2296 HandleScope scope(isolate); | 2296 HandleScope scope(isolate); |
2297 Handle<String> type = isolate->factory()->InternalizeUtf8String(type_str); | 2297 Handle<String> type = isolate->factory()->InternalizeUtf8String(type_str); |
2298 Handle<Object> args[] = { type, object, name, old_value }; | 2298 Handle<Object> args[] = { type, object, name, old_value }; |
(...skipping 4089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6388 JSObject::DefineAccessor(it, getter, setter, attrs); | 6388 JSObject::DefineAccessor(it, getter, setter, attrs); |
6389 if (result.is_null()) return false; | 6389 if (result.is_null()) return false; |
6390 } | 6390 } |
6391 } | 6391 } |
6392 | 6392 |
6393 // 11. Return true. | 6393 // 11. Return true. |
6394 return true; | 6394 return true; |
6395 } | 6395 } |
6396 | 6396 |
6397 | 6397 |
| 6398 // static |
| 6399 Maybe<bool> JSReceiver::CreateDataProperty(LookupIterator* it, |
| 6400 Handle<Object> value) { |
| 6401 // TODO(rossberg): Support proxies. |
| 6402 if (!it->GetReceiver()->IsJSObject()) return Nothing<bool>(); |
| 6403 return JSObject::CreateDataProperty(it, value); |
| 6404 } |
| 6405 |
| 6406 |
6398 // TODO(jkummerow): Consider unification with FastAsArrayLength() in | 6407 // TODO(jkummerow): Consider unification with FastAsArrayLength() in |
6399 // accessors.cc. | 6408 // accessors.cc. |
6400 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) { | 6409 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) { |
6401 DCHECK(value->IsNumber() || value->IsName()); | 6410 DCHECK(value->IsNumber() || value->IsName()); |
6402 if (value->ToArrayLength(length)) return true; | 6411 if (value->ToArrayLength(length)) return true; |
6403 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); | 6412 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); |
6404 return false; | 6413 return false; |
6405 } | 6414 } |
6406 | 6415 |
6407 | 6416 |
(...skipping 8225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14633 v8::Local<v8::Object> result; | 14642 v8::Local<v8::Object> result; |
14634 if (!interceptor->enumerator()->IsUndefined()) { | 14643 if (!interceptor->enumerator()->IsUndefined()) { |
14635 v8::GenericNamedPropertyEnumeratorCallback enum_fun = | 14644 v8::GenericNamedPropertyEnumeratorCallback enum_fun = |
14636 v8::ToCData<v8::GenericNamedPropertyEnumeratorCallback>( | 14645 v8::ToCData<v8::GenericNamedPropertyEnumeratorCallback>( |
14637 interceptor->enumerator()); | 14646 interceptor->enumerator()); |
14638 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); | 14647 LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); |
14639 result = args.Call(enum_fun); | 14648 result = args.Call(enum_fun); |
14640 } | 14649 } |
14641 if (result.IsEmpty()) return MaybeHandle<JSObject>(); | 14650 if (result.IsEmpty()) return MaybeHandle<JSObject>(); |
14642 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || | 14651 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || |
14643 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); | 14652 (v8::Utils::OpenHandle(*result)->IsJSObject() && |
| 14653 Handle<JSObject>::cast(v8::Utils::OpenHandle(*result)) |
| 14654 ->HasSloppyArgumentsElements())); |
14644 // Rebox before returning. | 14655 // Rebox before returning. |
14645 return handle(*v8::Utils::OpenHandle(*result), isolate); | 14656 return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); |
14646 } | 14657 } |
14647 | 14658 |
14648 | 14659 |
14649 // Compute the element keys from the interceptor. | 14660 // Compute the element keys from the interceptor. |
14650 MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor( | 14661 MaybeHandle<JSObject> JSObject::GetKeysForIndexedInterceptor( |
14651 Handle<JSObject> object, Handle<JSReceiver> receiver) { | 14662 Handle<JSObject> object, Handle<JSReceiver> receiver) { |
14652 Isolate* isolate = receiver->GetIsolate(); | 14663 Isolate* isolate = receiver->GetIsolate(); |
14653 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); | 14664 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); |
14654 PropertyCallbackArguments | 14665 PropertyCallbackArguments |
14655 args(isolate, interceptor->data(), *receiver, *object); | 14666 args(isolate, interceptor->data(), *receiver, *object); |
14656 v8::Local<v8::Object> result; | 14667 v8::Local<v8::Object> result; |
14657 if (!interceptor->enumerator()->IsUndefined()) { | 14668 if (!interceptor->enumerator()->IsUndefined()) { |
14658 v8::IndexedPropertyEnumeratorCallback enum_fun = | 14669 v8::IndexedPropertyEnumeratorCallback enum_fun = |
14659 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>( | 14670 v8::ToCData<v8::IndexedPropertyEnumeratorCallback>( |
14660 interceptor->enumerator()); | 14671 interceptor->enumerator()); |
14661 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); | 14672 LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); |
14662 result = args.Call(enum_fun); | 14673 result = args.Call(enum_fun); |
14663 } | 14674 } |
14664 if (result.IsEmpty()) return MaybeHandle<JSObject>(); | 14675 if (result.IsEmpty()) return MaybeHandle<JSObject>(); |
14665 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || | 14676 DCHECK(v8::Utils::OpenHandle(*result)->IsJSArray() || |
14666 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); | 14677 (v8::Utils::OpenHandle(*result)->IsJSObject() && |
| 14678 Handle<JSObject>::cast(v8::Utils::OpenHandle(*result)) |
| 14679 ->HasSloppyArgumentsElements())); |
14667 // Rebox before returning. | 14680 // Rebox before returning. |
14668 return handle(*v8::Utils::OpenHandle(*result), isolate); | 14681 return handle(JSObject::cast(*v8::Utils::OpenHandle(*result)), isolate); |
14669 } | 14682 } |
14670 | 14683 |
14671 | 14684 |
14672 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, | 14685 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, |
14673 Handle<Name> name) { | 14686 Handle<Name> name) { |
14674 LookupIterator it = LookupIterator::PropertyOrElement( | 14687 LookupIterator it = LookupIterator::PropertyOrElement( |
14675 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 14688 name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
14676 return HasProperty(&it); | 14689 return HasProperty(&it); |
14677 } | 14690 } |
14678 | 14691 |
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17882 if (cell->value() != *new_value) { | 17895 if (cell->value() != *new_value) { |
17883 cell->set_value(*new_value); | 17896 cell->set_value(*new_value); |
17884 Isolate* isolate = cell->GetIsolate(); | 17897 Isolate* isolate = cell->GetIsolate(); |
17885 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17898 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
17886 isolate, DependentCode::kPropertyCellChangedGroup); | 17899 isolate, DependentCode::kPropertyCellChangedGroup); |
17887 } | 17900 } |
17888 } | 17901 } |
17889 | 17902 |
17890 } // namespace internal | 17903 } // namespace internal |
17891 } // namespace v8 | 17904 } // namespace v8 |
OLD | NEW |