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

Side by Side Diff: src/objects.cc

Issue 1324713002: [es6] Implement Date.prototype[@@toPrimitive] as C++ builtin. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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
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 "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 6023 matching lines...) Expand 10 before | Expand all | Expand 10 after
6034 Handle<Object> result; 6034 Handle<Object> result;
6035 ASSIGN_RETURN_ON_EXCEPTION( 6035 ASSIGN_RETURN_ON_EXCEPTION(
6036 isolate, result, 6036 isolate, result,
6037 Execution::Call(isolate, exotic_to_prim, receiver, 1, &hint_string), 6037 Execution::Call(isolate, exotic_to_prim, receiver, 1, &hint_string),
6038 Object); 6038 Object);
6039 if (result->IsPrimitive()) return result; 6039 if (result->IsPrimitive()) return result;
6040 THROW_NEW_ERROR(isolate, 6040 THROW_NEW_ERROR(isolate,
6041 NewTypeError(MessageTemplate::kCannotConvertToPrimitive), 6041 NewTypeError(MessageTemplate::kCannotConvertToPrimitive),
6042 Object); 6042 Object);
6043 } 6043 }
6044 return OrdinaryToPrimitive(receiver, 6044 return OrdinaryToPrimitive(receiver, (hint == ToPrimitiveHint::kString)
6045 (hint == ToPrimitiveHint::kString) 6045 ? OrdinaryToPrimitiveHint::kString
6046 ? isolate->factory()->string_string() 6046 : OrdinaryToPrimitiveHint::kNumber);
6047 : isolate->factory()->number_string());
6048 } 6047 }
6049 6048
6050 6049
6051 // static 6050 // static
6052 MaybeHandle<Object> JSReceiver::OrdinaryToPrimitive(Handle<JSReceiver> receiver, 6051 MaybeHandle<Object> JSReceiver::OrdinaryToPrimitive(
6053 Handle<String> hint) { 6052 Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint) {
6054 Isolate* const isolate = receiver->GetIsolate(); 6053 Isolate* const isolate = receiver->GetIsolate();
6055 Handle<String> method_names[2]; 6054 Handle<String> method_names[2];
6056 if (hint.is_identical_to(isolate->factory()->number_string())) { 6055 switch (hint) {
6057 method_names[0] = isolate->factory()->valueOf_string(); 6056 case OrdinaryToPrimitiveHint::kNumber:
6058 method_names[1] = isolate->factory()->toString_string(); 6057 method_names[0] = isolate->factory()->valueOf_string();
6059 } else { 6058 method_names[1] = isolate->factory()->toString_string();
6060 DCHECK(hint.is_identical_to(isolate->factory()->string_string())); 6059 break;
6061 method_names[0] = isolate->factory()->toString_string(); 6060 case OrdinaryToPrimitiveHint::kString:
6062 method_names[1] = isolate->factory()->valueOf_string(); 6061 method_names[0] = isolate->factory()->toString_string();
6062 method_names[1] = isolate->factory()->valueOf_string();
6063 break;
6063 } 6064 }
6064 for (Handle<String> name : method_names) { 6065 for (Handle<String> name : method_names) {
6065 Handle<Object> method; 6066 Handle<Object> method;
6066 ASSIGN_RETURN_ON_EXCEPTION(isolate, method, 6067 ASSIGN_RETURN_ON_EXCEPTION(isolate, method,
6067 JSReceiver::GetProperty(receiver, name), Object); 6068 JSReceiver::GetProperty(receiver, name), Object);
6068 if (method->IsCallable()) { 6069 if (method->IsCallable()) {
6069 Handle<Object> result; 6070 Handle<Object> result;
6070 ASSIGN_RETURN_ON_EXCEPTION( 6071 ASSIGN_RETURN_ON_EXCEPTION(
6071 isolate, result, Execution::Call(isolate, method, receiver, 0, NULL), 6072 isolate, result, Execution::Call(isolate, method, receiver, 0, NULL),
6072 Object); 6073 Object);
(...skipping 2270 matching lines...) Expand 10 before | Expand all | Expand 10 after
8343 } 8344 }
8344 #endif 8345 #endif
8345 8346
8346 8347
8347 bool String::LooksValid() { 8348 bool String::LooksValid() {
8348 if (!GetIsolate()->heap()->Contains(this)) return false; 8349 if (!GetIsolate()->heap()->Contains(this)) return false;
8349 return true; 8350 return true;
8350 } 8351 }
8351 8352
8352 8353
8354 // static
8355 Handle<String> Name::ToFunctionName(Handle<Name> name) {
8356 if (name->IsString()) return Handle<String>::cast(name);
8357 // ES6 section 9.2.11 SetFunctionName, step 4.
8358 Isolate* const isolate = name->GetIsolate();
8359 Handle<Object> description(Handle<Symbol>::cast(name)->name(), isolate);
8360 if (description->IsUndefined()) return isolate->factory()->empty_string();
8361 int description_length = 0;
8362 base::SmartArrayPointer<char> description_bytes =
8363 Handle<String>::cast(description)
8364 ->ToCString(ALLOW_NULLS, FAST_STRING_TRAVERSAL, 0, -1,
8365 &description_length);
8366 ScopedVector<char> name_string(description_length + 2);
8367 name_string[0] = '[';
8368 for (int i = 0; i < description_length; ++i) {
8369 name_string[i + 1] = description_bytes[i];
8370 }
8371 name_string[description_length + 1] = ']';
8372 return isolate->factory()->InternalizeUtf8String(
8373 Vector<const char>(name_string.start(), name_string.length()));
8374 }
8375
8376
8353 namespace { 8377 namespace {
8354 8378
8355 bool AreDigits(const uint8_t* s, int from, int to) { 8379 bool AreDigits(const uint8_t* s, int from, int to) {
8356 for (int i = from; i < to; i++) { 8380 for (int i = from; i < to; i++) {
8357 if (s[i] < '0' || s[i] > '9') return false; 8381 if (s[i] < '0' || s[i] > '9') return false;
8358 } 8382 }
8359 8383
8360 return true; 8384 return true;
8361 } 8385 }
8362 8386
(...skipping 7496 matching lines...) Expand 10 before | Expand all | Expand 10 after
15859 set_hour(nan, SKIP_WRITE_BARRIER); 15883 set_hour(nan, SKIP_WRITE_BARRIER);
15860 set_min(nan, SKIP_WRITE_BARRIER); 15884 set_min(nan, SKIP_WRITE_BARRIER);
15861 set_sec(nan, SKIP_WRITE_BARRIER); 15885 set_sec(nan, SKIP_WRITE_BARRIER);
15862 set_weekday(nan, SKIP_WRITE_BARRIER); 15886 set_weekday(nan, SKIP_WRITE_BARRIER);
15863 } else { 15887 } else {
15864 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER); 15888 set_cache_stamp(Smi::FromInt(DateCache::kInvalidStamp), SKIP_WRITE_BARRIER);
15865 } 15889 }
15866 } 15890 }
15867 15891
15868 15892
15893 // static
15894 MaybeHandle<Object> JSDate::ToPrimitive(Handle<JSReceiver> receiver,
15895 Handle<Object> hint) {
15896 Isolate* const isolate = receiver->GetIsolate();
15897 if (hint->IsString()) {
15898 Handle<String> hint_string = Handle<String>::cast(hint);
15899 if (hint_string->Equals(isolate->heap()->number_string())) {
15900 return JSReceiver::OrdinaryToPrimitive(receiver,
15901 OrdinaryToPrimitiveHint::kNumber);
15902 }
15903 if (hint_string->Equals(isolate->heap()->default_string()) ||
15904 hint_string->Equals(isolate->heap()->string_string())) {
15905 return JSReceiver::OrdinaryToPrimitive(receiver,
15906 OrdinaryToPrimitiveHint::kString);
15907 }
15908 }
15909 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kInvalidHint, hint),
15910 Object);
15911 }
15912
15913
15869 void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) { 15914 void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) {
15870 int days = DateCache::DaysFromTime(local_time_ms); 15915 int days = DateCache::DaysFromTime(local_time_ms);
15871 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days); 15916 int time_in_day_ms = DateCache::TimeInDay(local_time_ms, days);
15872 int year, month, day; 15917 int year, month, day;
15873 date_cache->YearMonthDayFromDays(days, &year, &month, &day); 15918 date_cache->YearMonthDayFromDays(days, &year, &month, &day);
15874 int weekday = date_cache->Weekday(days); 15919 int weekday = date_cache->Weekday(days);
15875 int hour = time_in_day_ms / (60 * 60 * 1000); 15920 int hour = time_in_day_ms / (60 * 60 * 1000);
15876 int min = (time_in_day_ms / (60 * 1000)) % 60; 15921 int min = (time_in_day_ms / (60 * 1000)) % 60;
15877 int sec = (time_in_day_ms / 1000) % 60; 15922 int sec = (time_in_day_ms / 1000) % 60;
15878 set_cache_stamp(date_cache->stamp()); 15923 set_cache_stamp(date_cache->stamp());
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
16126 if (cell->value() != *new_value) { 16171 if (cell->value() != *new_value) {
16127 cell->set_value(*new_value); 16172 cell->set_value(*new_value);
16128 Isolate* isolate = cell->GetIsolate(); 16173 Isolate* isolate = cell->GetIsolate();
16129 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16174 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16130 isolate, DependentCode::kPropertyCellChangedGroup); 16175 isolate, DependentCode::kPropertyCellChangedGroup);
16131 } 16176 }
16132 } 16177 }
16133 16178
16134 } // namespace internal 16179 } // namespace internal
16135 } // namespace v8 16180 } // namespace v8
OLDNEW
« src/objects.h ('K') | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698