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 <iomanip> | 7 #include <iomanip> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "src/hydrogen.h" | 30 #include "src/hydrogen.h" |
31 #include "src/ic/ic.h" | 31 #include "src/ic/ic.h" |
32 #include "src/interpreter/bytecodes.h" | 32 #include "src/interpreter/bytecodes.h" |
33 #include "src/log.h" | 33 #include "src/log.h" |
34 #include "src/lookup.h" | 34 #include "src/lookup.h" |
35 #include "src/macro-assembler.h" | 35 #include "src/macro-assembler.h" |
36 #include "src/messages.h" | 36 #include "src/messages.h" |
37 #include "src/objects-inl.h" | 37 #include "src/objects-inl.h" |
38 #include "src/prototype.h" | 38 #include "src/prototype.h" |
39 #include "src/safepoint-table.h" | 39 #include "src/safepoint-table.h" |
| 40 #include "src/string-builder.h" |
40 #include "src/string-search.h" | 41 #include "src/string-search.h" |
41 #include "src/string-stream.h" | 42 #include "src/string-stream.h" |
42 #include "src/utils.h" | 43 #include "src/utils.h" |
43 | 44 |
44 #ifdef ENABLE_DISASSEMBLER | 45 #ifdef ENABLE_DISASSEMBLER |
45 #include "src/disasm.h" | 46 #include "src/disasm.h" |
46 #include "src/disassembler.h" | 47 #include "src/disassembler.h" |
47 #endif | 48 #endif |
48 | 49 |
49 namespace v8 { | 50 namespace v8 { |
(...skipping 5984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6034 Handle<Object> result; | 6035 Handle<Object> result; |
6035 ASSIGN_RETURN_ON_EXCEPTION( | 6036 ASSIGN_RETURN_ON_EXCEPTION( |
6036 isolate, result, | 6037 isolate, result, |
6037 Execution::Call(isolate, exotic_to_prim, receiver, 1, &hint_string), | 6038 Execution::Call(isolate, exotic_to_prim, receiver, 1, &hint_string), |
6038 Object); | 6039 Object); |
6039 if (result->IsPrimitive()) return result; | 6040 if (result->IsPrimitive()) return result; |
6040 THROW_NEW_ERROR(isolate, | 6041 THROW_NEW_ERROR(isolate, |
6041 NewTypeError(MessageTemplate::kCannotConvertToPrimitive), | 6042 NewTypeError(MessageTemplate::kCannotConvertToPrimitive), |
6042 Object); | 6043 Object); |
6043 } | 6044 } |
6044 return OrdinaryToPrimitive(receiver, | 6045 return OrdinaryToPrimitive(receiver, (hint == ToPrimitiveHint::kString) |
6045 (hint == ToPrimitiveHint::kString) | 6046 ? OrdinaryToPrimitiveHint::kString |
6046 ? isolate->factory()->string_string() | 6047 : OrdinaryToPrimitiveHint::kNumber); |
6047 : isolate->factory()->number_string()); | |
6048 } | 6048 } |
6049 | 6049 |
6050 | 6050 |
6051 // static | 6051 // static |
6052 MaybeHandle<Object> JSReceiver::OrdinaryToPrimitive(Handle<JSReceiver> receiver, | 6052 MaybeHandle<Object> JSReceiver::OrdinaryToPrimitive( |
6053 Handle<String> hint) { | 6053 Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint) { |
6054 Isolate* const isolate = receiver->GetIsolate(); | 6054 Isolate* const isolate = receiver->GetIsolate(); |
6055 Handle<String> method_names[2]; | 6055 Handle<String> method_names[2]; |
6056 if (hint.is_identical_to(isolate->factory()->number_string())) { | 6056 switch (hint) { |
6057 method_names[0] = isolate->factory()->valueOf_string(); | 6057 case OrdinaryToPrimitiveHint::kNumber: |
6058 method_names[1] = isolate->factory()->toString_string(); | 6058 method_names[0] = isolate->factory()->valueOf_string(); |
6059 } else { | 6059 method_names[1] = isolate->factory()->toString_string(); |
6060 DCHECK(hint.is_identical_to(isolate->factory()->string_string())); | 6060 break; |
6061 method_names[0] = isolate->factory()->toString_string(); | 6061 case OrdinaryToPrimitiveHint::kString: |
6062 method_names[1] = isolate->factory()->valueOf_string(); | 6062 method_names[0] = isolate->factory()->toString_string(); |
| 6063 method_names[1] = isolate->factory()->valueOf_string(); |
| 6064 break; |
6063 } | 6065 } |
6064 for (Handle<String> name : method_names) { | 6066 for (Handle<String> name : method_names) { |
6065 Handle<Object> method; | 6067 Handle<Object> method; |
6066 ASSIGN_RETURN_ON_EXCEPTION(isolate, method, | 6068 ASSIGN_RETURN_ON_EXCEPTION(isolate, method, |
6067 JSReceiver::GetProperty(receiver, name), Object); | 6069 JSReceiver::GetProperty(receiver, name), Object); |
6068 if (method->IsCallable()) { | 6070 if (method->IsCallable()) { |
6069 Handle<Object> result; | 6071 Handle<Object> result; |
6070 ASSIGN_RETURN_ON_EXCEPTION( | 6072 ASSIGN_RETURN_ON_EXCEPTION( |
6071 isolate, result, Execution::Call(isolate, method, receiver, 0, NULL), | 6073 isolate, result, Execution::Call(isolate, method, receiver, 0, NULL), |
6072 Object); | 6074 Object); |
(...skipping 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8343 } | 8345 } |
8344 #endif | 8346 #endif |
8345 | 8347 |
8346 | 8348 |
8347 bool String::LooksValid() { | 8349 bool String::LooksValid() { |
8348 if (!GetIsolate()->heap()->Contains(this)) return false; | 8350 if (!GetIsolate()->heap()->Contains(this)) return false; |
8349 return true; | 8351 return true; |
8350 } | 8352 } |
8351 | 8353 |
8352 | 8354 |
| 8355 // static |
| 8356 MaybeHandle<String> Name::ToFunctionName(Handle<Name> name) { |
| 8357 if (name->IsString()) return Handle<String>::cast(name); |
| 8358 // ES6 section 9.2.11 SetFunctionName, step 4. |
| 8359 Isolate* const isolate = name->GetIsolate(); |
| 8360 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate); |
| 8361 if (description->IsUndefined()) return isolate->factory()->empty_string(); |
| 8362 IncrementalStringBuilder builder(isolate); |
| 8363 builder.AppendCharacter('['); |
| 8364 builder.AppendString(Handle<String>::cast(description)); |
| 8365 builder.AppendCharacter(']'); |
| 8366 return builder.Finish(); |
| 8367 } |
| 8368 |
| 8369 |
8353 namespace { | 8370 namespace { |
8354 | 8371 |
8355 bool AreDigits(const uint8_t* s, int from, int to) { | 8372 bool AreDigits(const uint8_t* s, int from, int to) { |
8356 for (int i = from; i < to; i++) { | 8373 for (int i = from; i < to; i++) { |
8357 if (s[i] < '0' || s[i] > '9') return false; | 8374 if (s[i] < '0' || s[i] > '9') return false; |
8358 } | 8375 } |
8359 | 8376 |
8360 return true; | 8377 return true; |
8361 } | 8378 } |
8362 | 8379 |
(...skipping 7496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15859 set_hour(nan, SKIP_WRITE_BARRIER); | 15876 set_hour(nan, SKIP_WRITE_BARRIER); |
15860 set_min(nan, SKIP_WRITE_BARRIER); | 15877 set_min(nan, SKIP_WRITE_BARRIER); |
15861 set_sec(nan, SKIP_WRITE_BARRIER); | 15878 set_sec(nan, SKIP_WRITE_BARRIER); |
15862 set_weekday(nan, SKIP_WRITE_BARRIER); | 15879 set_weekday(nan, SKIP_WRITE_BARRIER); |
15863 } else { | 15880 } else { |
15864 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); | 15881 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); |
15865 } | 15882 } |
15866 } | 15883 } |
15867 | 15884 |
15868 | 15885 |
| 15886 // static |
| 15887 MaybeHandle<Object> JSDate::ToPrimitive(Handle<JSReceiver> receiver, |
| 15888 Handle<Object> hint) { |
| 15889 Isolate* const isolate = receiver->GetIsolate(); |
| 15890 if (hint->IsString()) { |
| 15891 Handle<String> hint_string = Handle<String>::cast(hint); |
| 15892 if (hint_string->Equals(isolate->heap()->number_string())) { |
| 15893 return JSReceiver::OrdinaryToPrimitive(receiver, |
| 15894 OrdinaryToPrimitiveHint::kNumber); |
| 15895 } |
| 15896 if (hint_string->Equals(isolate->heap()->default_string()) || |
| 15897 hint_string->Equals(isolate->heap()->string_string())) { |
| 15898 return JSReceiver::OrdinaryToPrimitive(receiver, |
| 15899 OrdinaryToPrimitiveHint::kString); |
| 15900 } |
| 15901 } |
| 15902 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kInvalidHint, hint), |
| 15903 Object); |
| 15904 } |
| 15905 |
| 15906 |
15869 void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) { | 15907 void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) { |
15870 int days = DateCache::DaysFromTime(local_time_ms); | 15908 int days = DateCache::DaysFromTime(local_time_ms); |
15871 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); | 15909 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); |
15872 int year, month, day; | 15910 int year, month, day; |
15873 date_cache->YearMonthDayFromDays(days, &year, &month, &day); | 15911 date_cache->YearMonthDayFromDays(days, &year, &month, &day); |
15874 int weekday = date_cache->Weekday(days); | 15912 int weekday = date_cache->Weekday(days); |
15875 int hour = time_in_day_ms / (60 * 60 * 1000); | 15913 int hour = time_in_day_ms / (60 * 60 * 1000); |
15876 int min = (time_in_day_ms / (60 * 1000)) % 60; | 15914 int min = (time_in_day_ms / (60 * 1000)) % 60; |
15877 int sec = (time_in_day_ms / 1000) % 60; | 15915 int sec = (time_in_day_ms / 1000) % 60; |
15878 set_cache_stamp(date_cache->stamp()); | 15916 set_cache_stamp(date_cache->stamp()); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16126 if (cell->value() != *new_value) { | 16164 if (cell->value() != *new_value) { |
16127 cell->set_value(*new_value); | 16165 cell->set_value(*new_value); |
16128 Isolate* isolate = cell->GetIsolate(); | 16166 Isolate* isolate = cell->GetIsolate(); |
16129 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16167 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16130 isolate, DependentCode::kPropertyCellChangedGroup); | 16168 isolate, DependentCode::kPropertyCellChangedGroup); |
16131 } | 16169 } |
16132 } | 16170 } |
16133 | 16171 |
16134 } // namespace internal | 16172 } // namespace internal |
16135 } // namespace v8 | 16173 } // namespace v8 |
OLD | NEW |