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

Side by Side Diff: src/runtime/runtime-date.cc

Issue 1556333002: [runtime] Migrate several Date builtins to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 4 years, 11 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-i18n.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions-inl.h" 8 #include "src/conversions-inl.h"
9 #include "src/date.h" 9 #include "src/date.h"
10 #include "src/dateparser-inl.h"
11 #include "src/factory.h" 10 #include "src/factory.h"
12 #include "src/isolate-inl.h" 11 #include "src/isolate-inl.h"
13 #include "src/messages.h" 12 #include "src/messages.h"
14 13
15 namespace v8 { 14 namespace v8 {
16 namespace internal { 15 namespace internal {
17 16
18 RUNTIME_FUNCTION(Runtime_DateMakeDay) { 17 RUNTIME_FUNCTION(Runtime_DateMakeDay) {
19 SealHandleScope shs(isolate); 18 SealHandleScope shs(isolate);
20 DCHECK(args.length() == 2); 19 DCHECK(args.length() == 2);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 RUNTIME_FUNCTION(Runtime_ThrowNotDateError) { 71 RUNTIME_FUNCTION(Runtime_ThrowNotDateError) {
73 HandleScope scope(isolate); 72 HandleScope scope(isolate);
74 DCHECK(args.length() == 0); 73 DCHECK(args.length() == 0);
75 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 74 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
76 NewTypeError(MessageTemplate::kNotDateObject)); 75 NewTypeError(MessageTemplate::kNotDateObject));
77 } 76 }
78 77
79 78
80 RUNTIME_FUNCTION(Runtime_DateCurrentTime) { 79 RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
81 HandleScope scope(isolate); 80 HandleScope scope(isolate);
82 DCHECK(args.length() == 0); 81 DCHECK_EQ(0, args.length());
83 if (FLAG_log_timer_events || FLAG_prof_cpp) LOG(isolate, CurrentTimeEvent()); 82 return *isolate->factory()->NewNumber(JSDate::CurrentTimeValue(isolate));
84
85 // According to ECMA-262, section 15.9.1, page 117, the precision of
86 // the number in a Date object representing a particular instant in
87 // time is milliseconds. Therefore, we floor the result of getting
88 // the OS time.
89 double millis;
90 if (FLAG_verify_predictable) {
91 millis = Floor(isolate->heap()->MonotonicallyIncreasingTimeInMs());
92 } else {
93 millis = Floor(base::OS::TimeCurrentMillis());
94 }
95 return *isolate->factory()->NewNumber(millis);
96 } 83 }
97 84
98 85
99 RUNTIME_FUNCTION(Runtime_DateParseString) {
100 HandleScope scope(isolate);
101 DCHECK_EQ(2, args.length());
102 CONVERT_ARG_HANDLE_CHECKED(Object, input, 0);
103 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1);
104
105 RUNTIME_ASSERT(output->HasFastElements());
106 JSObject::EnsureCanContainHeapObjectElements(output);
107 RUNTIME_ASSERT(output->HasFastObjectElements());
108 Handle<FixedArray> output_array(FixedArray::cast(output->elements()));
109 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
110
111 Handle<String> str;
112 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, str,
113 Object::ToString(isolate, input));
114
115 str = String::Flatten(str);
116 DisallowHeapAllocation no_gc;
117
118 bool result;
119 String::FlatContent str_content = str->GetFlatContent();
120 if (str_content.IsOneByte()) {
121 result = DateParser::Parse(str_content.ToOneByteVector(), *output_array,
122 isolate->unicode_cache());
123 } else {
124 DCHECK(str_content.IsTwoByte());
125 result = DateParser::Parse(str_content.ToUC16Vector(), *output_array,
126 isolate->unicode_cache());
127 }
128
129 if (result) {
130 return *output;
131 } else {
132 return isolate->heap()->null_value();
133 }
134 }
135
136
137 RUNTIME_FUNCTION(Runtime_DateLocalTimezone) { 86 RUNTIME_FUNCTION(Runtime_DateLocalTimezone) {
138 HandleScope scope(isolate); 87 HandleScope scope(isolate);
139 DCHECK(args.length() == 1); 88 DCHECK(args.length() == 1);
140 89
141 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 90 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
142 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs && 91 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
143 x <= DateCache::kMaxTimeBeforeUTCInMs); 92 x <= DateCache::kMaxTimeBeforeUTCInMs);
144 const char* zone = 93 const char* zone =
145 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x)); 94 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x));
146 Handle<String> result = 95 Handle<String> result =
147 isolate->factory()->NewStringFromUtf8(CStrVector(zone)).ToHandleChecked(); 96 isolate->factory()->NewStringFromUtf8(CStrVector(zone)).ToHandleChecked();
148 return *result; 97 return *result;
149 } 98 }
150 99
151 100
152 RUNTIME_FUNCTION(Runtime_DateToUTC) {
153 HandleScope scope(isolate);
154 DCHECK(args.length() == 1);
155
156 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
157 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
158 x <= DateCache::kMaxTimeBeforeUTCInMs);
159 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x));
160
161 return *isolate->factory()->NewNumber(static_cast<double>(time));
162 }
163
164
165 RUNTIME_FUNCTION(Runtime_DateCacheVersion) { 101 RUNTIME_FUNCTION(Runtime_DateCacheVersion) {
166 HandleScope hs(isolate); 102 HandleScope hs(isolate);
167 DCHECK(args.length() == 0); 103 DCHECK(args.length() == 0);
168 if (isolate->serializer_enabled()) return isolate->heap()->undefined_value(); 104 if (isolate->serializer_enabled()) return isolate->heap()->undefined_value();
169 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) { 105 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) {
170 Handle<FixedArray> date_cache_version = 106 Handle<FixedArray> date_cache_version =
171 isolate->factory()->NewFixedArray(1, TENURED); 107 isolate->factory()->NewFixedArray(1, TENURED);
172 date_cache_version->set(0, Smi::FromInt(0)); 108 date_cache_version->set(0, Smi::FromInt(0));
173 isolate->eternal_handles()->CreateSingleton( 109 isolate->eternal_handles()->CreateSingleton(
174 isolate, *date_cache_version, EternalHandles::DATE_CACHE_VERSION); 110 isolate, *date_cache_version, EternalHandles::DATE_CACHE_VERSION);
(...skipping 14 matching lines...) Expand all
189 DCHECK_EQ(2, args.length()); 125 DCHECK_EQ(2, args.length());
190 CONVERT_ARG_CHECKED(JSDate, date, 0); 126 CONVERT_ARG_CHECKED(JSDate, date, 0);
191 CONVERT_SMI_ARG_CHECKED(index, 1); 127 CONVERT_SMI_ARG_CHECKED(index, 1);
192 DCHECK_LE(0, index); 128 DCHECK_LE(0, index);
193 if (index == 0) return date->value(); 129 if (index == 0) return date->value();
194 return JSDate::GetField(date, Smi::FromInt(index)); 130 return JSDate::GetField(date, Smi::FromInt(index));
195 } 131 }
196 132
197 } // namespace internal 133 } // namespace internal
198 } // namespace v8 134 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-i18n.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698