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

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

Issue 612023002: Split even more runtime functions into separate files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime-compiler.cc ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/arguments.h"
8 #include "src/date.h"
9 #include "src/dateparser-inl.h"
10 #include "src/runtime/runtime.h"
11 #include "src/runtime/runtime-utils.h"
12
13 namespace v8 {
14 namespace internal {
15
16 RUNTIME_FUNCTION(Runtime_DateMakeDay) {
17 SealHandleScope shs(isolate);
18 DCHECK(args.length() == 2);
19
20 CONVERT_SMI_ARG_CHECKED(year, 0);
21 CONVERT_SMI_ARG_CHECKED(month, 1);
22
23 int days = isolate->date_cache()->DaysFromYearMonth(year, month);
24 RUNTIME_ASSERT(Smi::IsValid(days));
25 return Smi::FromInt(days);
26 }
27
28
29 RUNTIME_FUNCTION(Runtime_DateSetValue) {
30 HandleScope scope(isolate);
31 DCHECK(args.length() == 3);
32
33 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 0);
34 CONVERT_DOUBLE_ARG_CHECKED(time, 1);
35 CONVERT_SMI_ARG_CHECKED(is_utc, 2);
36
37 DateCache* date_cache = isolate->date_cache();
38
39 Handle<Object> value;
40 ;
41 bool is_value_nan = false;
42 if (std::isnan(time)) {
43 value = isolate->factory()->nan_value();
44 is_value_nan = true;
45 } else if (!is_utc && (time < -DateCache::kMaxTimeBeforeUTCInMs ||
46 time > DateCache::kMaxTimeBeforeUTCInMs)) {
47 value = isolate->factory()->nan_value();
48 is_value_nan = true;
49 } else {
50 time = is_utc ? time : date_cache->ToUTC(static_cast<int64_t>(time));
51 if (time < -DateCache::kMaxTimeInMs || time > DateCache::kMaxTimeInMs) {
52 value = isolate->factory()->nan_value();
53 is_value_nan = true;
54 } else {
55 value = isolate->factory()->NewNumber(DoubleToInteger(time));
56 }
57 }
58 date->SetValue(*value, is_value_nan);
59 return *value;
60 }
61
62
63 RUNTIME_FUNCTION(Runtime_ThrowNotDateError) {
64 HandleScope scope(isolate);
65 DCHECK(args.length() == 0);
66 THROW_NEW_ERROR_RETURN_FAILURE(
67 isolate, NewTypeError("not_date_object", HandleVector<Object>(NULL, 0)));
68 }
69
70
71 RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
72 HandleScope scope(isolate);
73 DCHECK(args.length() == 0);
74 if (FLAG_log_timer_events) LOG(isolate, CurrentTimeEvent());
75
76 // According to ECMA-262, section 15.9.1, page 117, the precision of
77 // the number in a Date object representing a particular instant in
78 // time is milliseconds. Therefore, we floor the result of getting
79 // the OS time.
80 double millis;
81 if (FLAG_verify_predictable) {
82 millis = 1388534400000.0; // Jan 1 2014 00:00:00 GMT+0000
83 millis += Floor(isolate->heap()->synthetic_time());
84 } else {
85 millis = Floor(base::OS::TimeCurrentMillis());
86 }
87 return *isolate->factory()->NewNumber(millis);
88 }
89
90
91 RUNTIME_FUNCTION(Runtime_DateParseString) {
92 HandleScope scope(isolate);
93 DCHECK(args.length() == 2);
94 CONVERT_ARG_HANDLE_CHECKED(String, str, 0);
95 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1);
96
97 RUNTIME_ASSERT(output->HasFastElements());
98 JSObject::EnsureCanContainHeapObjectElements(output);
99 RUNTIME_ASSERT(output->HasFastObjectElements());
100 Handle<FixedArray> output_array(FixedArray::cast(output->elements()));
101 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
102
103 str = String::Flatten(str);
104 DisallowHeapAllocation no_gc;
105
106 bool result;
107 String::FlatContent str_content = str->GetFlatContent();
108 if (str_content.IsOneByte()) {
109 result = DateParser::Parse(str_content.ToOneByteVector(), *output_array,
110 isolate->unicode_cache());
111 } else {
112 DCHECK(str_content.IsTwoByte());
113 result = DateParser::Parse(str_content.ToUC16Vector(), *output_array,
114 isolate->unicode_cache());
115 }
116
117 if (result) {
118 return *output;
119 } else {
120 return isolate->heap()->null_value();
121 }
122 }
123
124
125 RUNTIME_FUNCTION(Runtime_DateLocalTimezone) {
126 HandleScope scope(isolate);
127 DCHECK(args.length() == 1);
128
129 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
130 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
131 x <= DateCache::kMaxTimeBeforeUTCInMs);
132 const char* zone =
133 isolate->date_cache()->LocalTimezone(static_cast<int64_t>(x));
134 Handle<String> result =
135 isolate->factory()->NewStringFromUtf8(CStrVector(zone)).ToHandleChecked();
136 return *result;
137 }
138
139
140 RUNTIME_FUNCTION(Runtime_DateToUTC) {
141 HandleScope scope(isolate);
142 DCHECK(args.length() == 1);
143
144 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
145 RUNTIME_ASSERT(x >= -DateCache::kMaxTimeBeforeUTCInMs &&
146 x <= DateCache::kMaxTimeBeforeUTCInMs);
147 int64_t time = isolate->date_cache()->ToUTC(static_cast<int64_t>(x));
148
149 return *isolate->factory()->NewNumber(static_cast<double>(time));
150 }
151
152
153 RUNTIME_FUNCTION(Runtime_DateCacheVersion) {
154 HandleScope hs(isolate);
155 DCHECK(args.length() == 0);
156 if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) {
157 Handle<FixedArray> date_cache_version =
158 isolate->factory()->NewFixedArray(1, TENURED);
159 date_cache_version->set(0, Smi::FromInt(0));
160 isolate->eternal_handles()->CreateSingleton(
161 isolate, *date_cache_version, EternalHandles::DATE_CACHE_VERSION);
162 }
163 Handle<FixedArray> date_cache_version =
164 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
165 EternalHandles::DATE_CACHE_VERSION));
166 // Return result as a JS array.
167 Handle<JSObject> result =
168 isolate->factory()->NewJSObject(isolate->array_function());
169 JSArray::SetContent(Handle<JSArray>::cast(result), date_cache_version);
170 return *result;
171 }
172
173
174 RUNTIME_FUNCTION(RuntimeReference_DateField) {
175 SealHandleScope shs(isolate);
176 DCHECK(args.length() == 2);
177 CONVERT_ARG_CHECKED(Object, obj, 0);
178 CONVERT_SMI_ARG_CHECKED(index, 1);
179 if (!obj->IsJSDate()) {
180 HandleScope scope(isolate);
181 THROW_NEW_ERROR_RETURN_FAILURE(
182 isolate,
183 NewTypeError("not_date_object", HandleVector<Object>(NULL, 0)));
184 }
185 JSDate* date = JSDate::cast(obj);
186 if (index == 0) return date->value();
187 return JSDate::GetField(date, Smi::FromInt(index));
188 }
189 }
190 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-compiler.cc ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698