| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |