OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <time.h> | 5 #include <time.h> |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/os.h" | 12 #include "vm/os.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 static int32_t kMaxAllowedSeconds = 2100000000; | 16 static int32_t kMaxAllowedSeconds = 2100000000; |
17 | 17 |
18 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneName, 1) { | 18 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneName, 1) { |
19 GET_NON_NULL_NATIVE_ARGUMENT( | 19 GET_NON_NULL_NATIVE_ARGUMENT( |
20 Integer, dart_seconds, arguments->NativeArgAt(0)); | 20 Integer, dart_seconds, arguments->NativeArgAt(0)); |
21 int64_t seconds = dart_seconds.AsInt64Value(); | 21 int64_t seconds = dart_seconds.AsInt64Value(); |
22 if (seconds < 0 || seconds > kMaxAllowedSeconds) { | 22 if (seconds < 0 || seconds > kMaxAllowedSeconds) { |
23 GrowableArray<const Object*> args; | 23 const Array& args = Array::Handle(Array::New(1)); |
24 args.Add(&dart_seconds); | 24 args.SetAt(0, dart_seconds); |
25 Exceptions::ThrowByType(Exceptions::kArgument, args); | 25 Exceptions::ThrowByType(Exceptions::kArgument, args); |
26 } | 26 } |
27 const char* name = OS::GetTimeZoneName(seconds); | 27 const char* name = OS::GetTimeZoneName(seconds); |
28 return String::New(name); | 28 return String::New(name); |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneOffsetInSeconds, 1) { | 32 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneOffsetInSeconds, 1) { |
33 GET_NON_NULL_NATIVE_ARGUMENT( | 33 GET_NON_NULL_NATIVE_ARGUMENT( |
34 Integer, dart_seconds, arguments->NativeArgAt(0)); | 34 Integer, dart_seconds, arguments->NativeArgAt(0)); |
35 int64_t seconds = dart_seconds.AsInt64Value(); | 35 int64_t seconds = dart_seconds.AsInt64Value(); |
36 if (seconds < 0 || seconds > kMaxAllowedSeconds) { | 36 if (seconds < 0 || seconds > kMaxAllowedSeconds) { |
37 GrowableArray<const Object*> args; | 37 const Array& args = Array::Handle(Array::New(1)); |
38 args.Add(&dart_seconds); | 38 args.SetAt(0, dart_seconds); |
39 Exceptions::ThrowByType(Exceptions::kArgument, args); | 39 Exceptions::ThrowByType(Exceptions::kArgument, args); |
40 } | 40 } |
41 int offset = OS::GetTimeZoneOffsetInSeconds(seconds); | 41 int offset = OS::GetTimeZoneOffsetInSeconds(seconds); |
42 return Integer::New(offset); | 42 return Integer::New(offset); |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 DEFINE_NATIVE_ENTRY(DateNatives_localTimeZoneAdjustmentInSeconds, 0) { | 46 DEFINE_NATIVE_ENTRY(DateNatives_localTimeZoneAdjustmentInSeconds, 0) { |
47 int adjustment = OS::GetLocalTimeZoneAdjustmentInSeconds(); | 47 int adjustment = OS::GetLocalTimeZoneAdjustmentInSeconds(); |
48 return Integer::New(adjustment); | 48 return Integer::New(adjustment); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) { | 52 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) { |
53 return Integer::New(OS::GetCurrentTimeMillis()); | 53 return Integer::New(OS::GetCurrentTimeMillis()); |
54 } | 54 } |
55 | 55 |
56 } // namespace dart | 56 } // namespace dart |
OLD | NEW |