OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 // Check the receiver. | 1020 // Check the receiver. |
1021 for (PrototypeIterator iter(isolate, receiver, | 1021 for (PrototypeIterator iter(isolate, receiver, |
1022 PrototypeIterator::START_AT_RECEIVER); | 1022 PrototypeIterator::START_AT_RECEIVER); |
1023 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { | 1023 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { |
1024 if (signature->IsTemplateFor(iter.GetCurrent())) return iter.GetCurrent(); | 1024 if (signature->IsTemplateFor(iter.GetCurrent())) return iter.GetCurrent(); |
1025 } | 1025 } |
1026 return isolate->heap()->null_value(); | 1026 return isolate->heap()->null_value(); |
1027 } | 1027 } |
1028 | 1028 |
1029 | 1029 |
| 1030 // static |
| 1031 MaybeHandle<JSObject> JSObject::New(Handle<JSFunction> constructor, |
| 1032 Handle<JSReceiver> new_target, |
| 1033 Handle<AllocationSite> site) { |
| 1034 // If called through new, new.target can be: |
| 1035 // - a subclass of constructor, |
| 1036 // - a proxy wrapper around constructor, or |
| 1037 // - the constructor itself. |
| 1038 // If called through Reflect.construct, it's guaranteed to be a constructor. |
| 1039 Isolate* const isolate = constructor->GetIsolate(); |
| 1040 DCHECK(constructor->IsConstructor()); |
| 1041 DCHECK(new_target->IsConstructor()); |
| 1042 DCHECK(!constructor->has_initial_map() || |
| 1043 constructor->initial_map()->instance_type() != JS_FUNCTION_TYPE); |
| 1044 |
| 1045 Handle<Map> initial_map; |
| 1046 ASSIGN_RETURN_ON_EXCEPTION( |
| 1047 isolate, initial_map, |
| 1048 JSFunction::GetDerivedMap(isolate, constructor, new_target), JSObject); |
| 1049 Handle<JSObject> result = |
| 1050 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); |
| 1051 isolate->counters()->constructed_objects()->Increment(); |
| 1052 isolate->counters()->constructed_objects_runtime()->Increment(); |
| 1053 return result; |
| 1054 } |
| 1055 |
| 1056 |
1030 Handle<FixedArray> JSObject::EnsureWritableFastElements( | 1057 Handle<FixedArray> JSObject::EnsureWritableFastElements( |
1031 Handle<JSObject> object) { | 1058 Handle<JSObject> object) { |
1032 DCHECK(object->HasFastSmiOrObjectElements()); | 1059 DCHECK(object->HasFastSmiOrObjectElements()); |
1033 Isolate* isolate = object->GetIsolate(); | 1060 Isolate* isolate = object->GetIsolate(); |
1034 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate); | 1061 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate); |
1035 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; | 1062 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; |
1036 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap( | 1063 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap( |
1037 elems, isolate->factory()->fixed_array_map()); | 1064 elems, isolate->factory()->fixed_array_map()); |
1038 object->set_elements(*writable_elems); | 1065 object->set_elements(*writable_elems); |
1039 isolate->counters()->cow_arrays_converted()->Increment(); | 1066 isolate->counters()->cow_arrays_converted()->Increment(); |
(...skipping 18047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19087 int BreakPointInfo::GetBreakPointCount() { | 19114 int BreakPointInfo::GetBreakPointCount() { |
19088 // No break point. | 19115 // No break point. |
19089 if (break_point_objects()->IsUndefined()) return 0; | 19116 if (break_point_objects()->IsUndefined()) return 0; |
19090 // Single break point. | 19117 // Single break point. |
19091 if (!break_point_objects()->IsFixedArray()) return 1; | 19118 if (!break_point_objects()->IsFixedArray()) return 1; |
19092 // Multiple break points. | 19119 // Multiple break points. |
19093 return FixedArray::cast(break_point_objects())->length(); | 19120 return FixedArray::cast(break_point_objects())->length(); |
19094 } | 19121 } |
19095 | 19122 |
19096 | 19123 |
| 19124 // static |
| 19125 MaybeHandle<JSDate> JSDate::New(Handle<JSFunction> constructor, |
| 19126 Handle<JSReceiver> new_target, double tv) { |
| 19127 Isolate* const isolate = constructor->GetIsolate(); |
| 19128 Handle<JSObject> result; |
| 19129 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, |
| 19130 JSObject::New(constructor, new_target), JSDate); |
| 19131 if (-DateCache::kMaxTimeInMs <= tv && tv <= DateCache::kMaxTimeInMs) { |
| 19132 tv = DoubleToInteger(tv) + 0.0; |
| 19133 } else { |
| 19134 tv = std::numeric_limits<double>::quiet_NaN(); |
| 19135 } |
| 19136 Handle<Object> value = isolate->factory()->NewNumber(tv); |
| 19137 Handle<JSDate>::cast(result)->SetValue(*value, std::isnan(tv)); |
| 19138 return Handle<JSDate>::cast(result); |
| 19139 } |
| 19140 |
| 19141 |
| 19142 // static |
| 19143 double JSDate::CurrentTimeValue(Isolate* isolate) { |
| 19144 if (FLAG_log_timer_events || FLAG_prof_cpp) LOG(isolate, CurrentTimeEvent()); |
| 19145 |
| 19146 // According to ECMA-262, section 15.9.1, page 117, the precision of |
| 19147 // the number in a Date object representing a particular instant in |
| 19148 // time is milliseconds. Therefore, we floor the result of getting |
| 19149 // the OS time. |
| 19150 return Floor(FLAG_verify_predictable |
| 19151 ? isolate->heap()->MonotonicallyIncreasingTimeInMs() |
| 19152 : base::OS::TimeCurrentMillis()); |
| 19153 } |
| 19154 |
| 19155 |
| 19156 // static |
19097 Object* JSDate::GetField(Object* object, Smi* index) { | 19157 Object* JSDate::GetField(Object* object, Smi* index) { |
19098 return JSDate::cast(object)->DoGetField( | 19158 return JSDate::cast(object)->DoGetField( |
19099 static_cast<FieldIndex>(index->value())); | 19159 static_cast<FieldIndex>(index->value())); |
19100 } | 19160 } |
19101 | 19161 |
19102 | 19162 |
19103 Object* JSDate::DoGetField(FieldIndex index) { | 19163 Object* JSDate::DoGetField(FieldIndex index) { |
19104 DCHECK(index != kDateValue); | 19164 DCHECK(index != kDateValue); |
19105 | 19165 |
19106 DateCache* date_cache = GetIsolate()->date_cache(); | 19166 DateCache* date_cache = GetIsolate()->date_cache(); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19493 if (cell->value() != *new_value) { | 19553 if (cell->value() != *new_value) { |
19494 cell->set_value(*new_value); | 19554 cell->set_value(*new_value); |
19495 Isolate* isolate = cell->GetIsolate(); | 19555 Isolate* isolate = cell->GetIsolate(); |
19496 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19556 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19497 isolate, DependentCode::kPropertyCellChangedGroup); | 19557 isolate, DependentCode::kPropertyCellChangedGroup); |
19498 } | 19558 } |
19499 } | 19559 } |
19500 | 19560 |
19501 } // namespace internal | 19561 } // namespace internal |
19502 } // namespace v8 | 19562 } // namespace v8 |
OLD | NEW |