| 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_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0)); | 19 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0)); |
| 20 int64_t seconds = dart_seconds.AsInt64Value(); | 20 int64_t seconds = dart_seconds.AsInt64Value(); |
| 21 if (seconds < 0 || seconds > kMaxAllowedSeconds) { | 21 if (seconds < 0 || seconds > kMaxAllowedSeconds) { |
| 22 GrowableArray<const Object*> args; | 22 GrowableArray<const Object*> args; |
| 23 args.Add(&dart_seconds); | 23 args.Add(&dart_seconds); |
| 24 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 24 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 25 } | 25 } |
| 26 const char* name = OS::GetTimeZoneName(seconds); | 26 const char* name = OS::GetTimeZoneName(seconds); |
| 27 const String& dart_name = String::Handle(String::New(name)); | 27 return String::New(name); |
| 28 arguments->SetReturn(dart_name); | |
| 29 } | 28 } |
| 30 | 29 |
| 31 | 30 |
| 32 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneOffsetInSeconds, 1) { | 31 DEFINE_NATIVE_ENTRY(DateNatives_timeZoneOffsetInSeconds, 1) { |
| 33 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0)); | 32 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0)); |
| 34 int64_t seconds = dart_seconds.AsInt64Value(); | 33 int64_t seconds = dart_seconds.AsInt64Value(); |
| 35 if (seconds < 0 || seconds > kMaxAllowedSeconds) { | 34 if (seconds < 0 || seconds > kMaxAllowedSeconds) { |
| 36 GrowableArray<const Object*> args; | 35 GrowableArray<const Object*> args; |
| 37 args.Add(&dart_seconds); | 36 args.Add(&dart_seconds); |
| 38 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 37 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 39 } | 38 } |
| 40 int offset = OS::GetTimeZoneOffsetInSeconds(seconds); | 39 int offset = OS::GetTimeZoneOffsetInSeconds(seconds); |
| 41 const Integer& dart_offset = Integer::Handle(Integer::New(offset)); | 40 return Integer::New(offset); |
| 42 arguments->SetReturn(dart_offset); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 | 43 |
| 46 DEFINE_NATIVE_ENTRY(DateNatives_localTimeZoneAdjustmentInSeconds, 0) { | 44 DEFINE_NATIVE_ENTRY(DateNatives_localTimeZoneAdjustmentInSeconds, 0) { |
| 47 int adjustment = OS::GetLocalTimeZoneAdjustmentInSeconds(); | 45 int adjustment = OS::GetLocalTimeZoneAdjustmentInSeconds(); |
| 48 const Integer& dart_adjustment = Integer::Handle(Integer::New(adjustment)); | 46 return Integer::New(adjustment); |
| 49 arguments->SetReturn(dart_adjustment); | |
| 50 } | 47 } |
| 51 | 48 |
| 52 | 49 |
| 53 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) { | 50 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) { |
| 54 const Integer& time = Integer::Handle( | 51 return Integer::New(OS::GetCurrentTimeMillis()); |
| 55 Integer::New(OS::GetCurrentTimeMillis())); | |
| 56 arguments->SetReturn(time); | |
| 57 } | 52 } |
| 58 | 53 |
| 59 } // namespace dart | 54 } // namespace dart |
| OLD | NEW |