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

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

Issue 1167813003: [date] Refactor the %_DateField intrinsic to be optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments. Created 5 years, 6 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/x64/full-codegen-x64.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/date.h" 8 #include "src/date.h"
9 #include "src/dateparser-inl.h" 9 #include "src/dateparser-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 is_value_nan = true; 53 is_value_nan = true;
54 } else { 54 } else {
55 value = isolate->factory()->NewNumber(DoubleToInteger(time)); 55 value = isolate->factory()->NewNumber(DoubleToInteger(time));
56 } 56 }
57 } 57 }
58 date->SetValue(*value, is_value_nan); 58 date->SetValue(*value, is_value_nan);
59 return *value; 59 return *value;
60 } 60 }
61 61
62 62
63 RUNTIME_FUNCTION(Runtime_ThrowIfNotADate) {
64 SealHandleScope shs(isolate);
65 DCHECK_EQ(1, args.length());
66 CONVERT_ARG_CHECKED(Object, obj, 0);
67 if (!obj->IsJSDate()) {
68 HandleScope scope(isolate);
69 THROW_NEW_ERROR_RETURN_FAILURE(
70 isolate, NewTypeError(MessageTemplate::kNotDateObject));
71 }
72 return obj;
73 }
74
75
63 RUNTIME_FUNCTION(Runtime_ThrowNotDateError) { 76 RUNTIME_FUNCTION(Runtime_ThrowNotDateError) {
64 HandleScope scope(isolate); 77 HandleScope scope(isolate);
65 DCHECK(args.length() == 0); 78 DCHECK(args.length() == 0);
66 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 79 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
67 NewTypeError(MessageTemplate::kNotDateObject)); 80 NewTypeError(MessageTemplate::kNotDateObject));
68 } 81 }
69 82
70 83
71 RUNTIME_FUNCTION(Runtime_DateCurrentTime) { 84 RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
72 HandleScope scope(isolate); 85 HandleScope scope(isolate);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // Return result as a JS array. 180 // Return result as a JS array.
168 Handle<JSObject> result = 181 Handle<JSObject> result =
169 isolate->factory()->NewJSObject(isolate->array_function()); 182 isolate->factory()->NewJSObject(isolate->array_function());
170 JSArray::SetContent(Handle<JSArray>::cast(result), date_cache_version); 183 JSArray::SetContent(Handle<JSArray>::cast(result), date_cache_version);
171 return *result; 184 return *result;
172 } 185 }
173 186
174 187
175 RUNTIME_FUNCTION(Runtime_DateField) { 188 RUNTIME_FUNCTION(Runtime_DateField) {
176 SealHandleScope shs(isolate); 189 SealHandleScope shs(isolate);
177 DCHECK(args.length() == 2); 190 DCHECK_EQ(2, args.length());
178 CONVERT_ARG_CHECKED(Object, obj, 0); 191 CONVERT_ARG_CHECKED(JSDate, date, 0);
179 CONVERT_SMI_ARG_CHECKED(index, 1); 192 CONVERT_SMI_ARG_CHECKED(index, 1);
180 if (!obj->IsJSDate()) { 193 DCHECK_LE(0, index);
181 HandleScope scope(isolate);
182 THROW_NEW_ERROR_RETURN_FAILURE(
183 isolate, NewTypeError(MessageTemplate::kNotDateObject));
184 }
185 JSDate* date = JSDate::cast(obj);
186 if (index == 0) return date->value(); 194 if (index == 0) return date->value();
187 return JSDate::GetField(date, Smi::FromInt(index)); 195 return JSDate::GetField(date, Smi::FromInt(index));
188 } 196 }
197
189 } // namespace internal 198 } // namespace internal
190 } // namespace v8 199 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698