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

Side by Side Diff: runtime/lib/date.cc

Issue 9693051: Add type checking to some native function arguments (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « no previous file | runtime/lib/error.cc » ('j') | runtime/lib/isolate.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/exceptions.h"
Ivan Posva 2012/03/13 18:19:53 native_entry.h should include exceptions.h
8 #include "vm/native_entry.h" 9 #include "vm/native_entry.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 #include "vm/os.h" 11 #include "vm/os.h"
11 12
12 namespace dart { 13 namespace dart {
13 14
14 static bool BreakDownSecondsSinceEpoch(const Integer& dart_seconds, 15 static bool BreakDownSecondsSinceEpoch(const Integer& dart_seconds,
15 const Bool& dart_is_utc, 16 const Bool& dart_is_utc,
16 OS::BrokenDownDate* result) { 17 OS::BrokenDownDate* result) {
17 bool is_utc = dart_is_utc.value(); 18 bool is_utc = dart_is_utc.value();
18 int64_t value = dart_seconds.AsInt64Value(); 19 int64_t value = dart_seconds.AsInt64Value();
19 time_t seconds = static_cast<time_t>(value); 20 time_t seconds = static_cast<time_t>(value);
20 return OS::BreakDownSecondsSinceEpoch(seconds, is_utc, result); 21 return OS::BreakDownSecondsSinceEpoch(seconds, is_utc, result);
21 } 22 }
22 23
23 24
24 DEFINE_NATIVE_ENTRY(DateNatives_brokenDownToSecondsSinceEpoch, 7) { 25 DEFINE_NATIVE_ENTRY(DateNatives_brokenDownToSecondsSinceEpoch, 7) {
25 const Integer& dart_years = Integer::CheckedHandle(arguments->At(0)); 26 GET_NATIVE_ARGUMENT(Integer, dart_years, arguments->At(0));
26 const Smi& dart_month = Smi::CheckedHandle(arguments->At(1)); 27 GET_NATIVE_ARGUMENT(Smi, dart_month, arguments->At(1));
27 const Smi& dart_day = Smi::CheckedHandle(arguments->At(2)); 28 GET_NATIVE_ARGUMENT(Smi, dart_day, arguments->At(2));
28 const Smi& dart_hours = Smi::CheckedHandle(arguments->At(3)); 29 GET_NATIVE_ARGUMENT(Smi, dart_hours, arguments->At(3));
29 const Smi& dart_minutes = Smi::CheckedHandle(arguments->At(4)); 30 GET_NATIVE_ARGUMENT(Smi, dart_minutes, arguments->At(4));
30 const Smi& dart_seconds = Smi::CheckedHandle(arguments->At(5)); 31 GET_NATIVE_ARGUMENT(Smi, dart_seconds, arguments->At(5));
31 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(6)); 32 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(6));
32 if (!dart_years.IsSmi()) { 33 if (!dart_years.IsSmi()) {
33 UNIMPLEMENTED(); 34 UNIMPLEMENTED();
34 } 35 }
35 Smi& smi_years = Smi::Handle(); 36 Smi& smi_years = Smi::Handle();
36 smi_years ^= dart_years.raw(); 37 smi_years ^= dart_years.raw();
37 OS::BrokenDownDate broken_down; 38 OS::BrokenDownDate broken_down;
38 // mktime takes the years since 1900. 39 // mktime takes the years since 1900.
39 // TODO(floitsch): Removing 1900 could underflow the intptr_t. 40 // TODO(floitsch): Removing 1900 could underflow the intptr_t.
40 intptr_t year = smi_years.Value() - 1900; 41 intptr_t year = smi_years.Value() - 1900;
41 // TODO(1143): We don't handle the case yet where intptr_t and int have 42 // TODO(1143): We don't handle the case yet where intptr_t and int have
(...skipping 18 matching lines...) Expand all
60 61
61 62
62 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) { 63 DEFINE_NATIVE_ENTRY(DateNatives_currentTimeMillis, 0) {
63 const Integer& time = Integer::Handle( 64 const Integer& time = Integer::Handle(
64 Integer::New(OS::GetCurrentTimeMillis())); 65 Integer::New(OS::GetCurrentTimeMillis()));
65 arguments->SetReturn(time); 66 arguments->SetReturn(time);
66 } 67 }
67 68
68 69
69 DEFINE_NATIVE_ENTRY(DateNatives_getYear, 2) { 70 DEFINE_NATIVE_ENTRY(DateNatives_getYear, 2) {
70 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 71 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
71 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 72 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
72 OS::BrokenDownDate broken_down; 73 OS::BrokenDownDate broken_down;
73 bool succeeded = 74 bool succeeded =
74 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 75 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
75 if (!succeeded) { 76 if (!succeeded) {
76 UNIMPLEMENTED(); 77 UNIMPLEMENTED();
77 } 78 }
78 // C uses years since 1900, and not full years. 79 // C uses years since 1900, and not full years.
79 // TODO(floitsch): adding 1900 could overflow the intptr_t. 80 // TODO(floitsch): adding 1900 could overflow the intptr_t.
80 intptr_t year = broken_down.year + 1900; 81 intptr_t year = broken_down.year + 1900;
81 arguments->SetReturn(Integer::Handle(Integer::New(year))); 82 arguments->SetReturn(Integer::Handle(Integer::New(year)));
82 } 83 }
83 84
84 85
85 DEFINE_NATIVE_ENTRY(DateNatives_getMonth, 2) { 86 DEFINE_NATIVE_ENTRY(DateNatives_getMonth, 2) {
86 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 87 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
87 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 88 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
88 OS::BrokenDownDate broken_down; 89 OS::BrokenDownDate broken_down;
89 bool succeeded = 90 bool succeeded =
90 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 91 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
91 if (!succeeded) { 92 if (!succeeded) {
92 UNIMPLEMENTED(); 93 UNIMPLEMENTED();
93 } 94 }
94 // Dart has 1-based months (contrary to C's 0-based). 95 // Dart has 1-based months (contrary to C's 0-based).
95 const Smi& result = Smi::Handle(Smi::New(broken_down.month + 1)); 96 const Smi& result = Smi::Handle(Smi::New(broken_down.month + 1));
96 arguments->SetReturn(result); 97 arguments->SetReturn(result);
97 } 98 }
98 99
99 100
100 DEFINE_NATIVE_ENTRY(DateNatives_getDay, 2) { 101 DEFINE_NATIVE_ENTRY(DateNatives_getDay, 2) {
101 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 102 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
102 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 103 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
103 OS::BrokenDownDate broken_down; 104 OS::BrokenDownDate broken_down;
104 bool succeeded = 105 bool succeeded =
105 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 106 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
106 if (!succeeded) { 107 if (!succeeded) {
107 UNIMPLEMENTED(); 108 UNIMPLEMENTED();
108 } 109 }
109 const Smi& result = Smi::Handle(Smi::New(broken_down.day)); 110 const Smi& result = Smi::Handle(Smi::New(broken_down.day));
110 arguments->SetReturn(result); 111 arguments->SetReturn(result);
111 } 112 }
112 113
113 114
114 DEFINE_NATIVE_ENTRY(DateNatives_getHours, 2) { 115 DEFINE_NATIVE_ENTRY(DateNatives_getHours, 2) {
115 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 116 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
116 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 117 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
117 OS::BrokenDownDate broken_down; 118 OS::BrokenDownDate broken_down;
118 bool succeeded = 119 bool succeeded =
119 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 120 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
120 if (!succeeded) { 121 if (!succeeded) {
121 UNIMPLEMENTED(); 122 UNIMPLEMENTED();
122 } 123 }
123 const Smi& result = Smi::Handle(Smi::New(broken_down.hours)); 124 const Smi& result = Smi::Handle(Smi::New(broken_down.hours));
124 arguments->SetReturn(result); 125 arguments->SetReturn(result);
125 } 126 }
126 127
127 128
128 DEFINE_NATIVE_ENTRY(DateNatives_getMinutes, 2) { 129 DEFINE_NATIVE_ENTRY(DateNatives_getMinutes, 2) {
129 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 130 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
130 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 131 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
131 OS::BrokenDownDate broken_down; 132 OS::BrokenDownDate broken_down;
132 bool succeeded = 133 bool succeeded =
133 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 134 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
134 if (!succeeded) { 135 if (!succeeded) {
135 UNIMPLEMENTED(); 136 UNIMPLEMENTED();
136 } 137 }
137 const Smi& result = Smi::Handle(Smi::New(broken_down.minutes)); 138 const Smi& result = Smi::Handle(Smi::New(broken_down.minutes));
138 arguments->SetReturn(result); 139 arguments->SetReturn(result);
139 } 140 }
140 141
141 142
142 DEFINE_NATIVE_ENTRY(DateNatives_getSeconds, 2) { 143 DEFINE_NATIVE_ENTRY(DateNatives_getSeconds, 2) {
143 const Integer& dart_seconds = Integer::CheckedHandle(arguments->At(0)); 144 GET_NATIVE_ARGUMENT(Integer, dart_seconds, arguments->At(0));
144 const Bool& dart_is_utc = Bool::CheckedHandle(arguments->At(1)); 145 GET_NATIVE_ARGUMENT(Bool, dart_is_utc, arguments->At(1));
145 OS::BrokenDownDate broken_down; 146 OS::BrokenDownDate broken_down;
146 bool succeeded = 147 bool succeeded =
147 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down); 148 BreakDownSecondsSinceEpoch(dart_seconds, dart_is_utc, &broken_down);
148 if (!succeeded) { 149 if (!succeeded) {
149 UNIMPLEMENTED(); 150 UNIMPLEMENTED();
150 } 151 }
151 const Smi& result = Smi::Handle(Smi::New(broken_down.seconds)); 152 const Smi& result = Smi::Handle(Smi::New(broken_down.seconds));
152 arguments->SetReturn(result); 153 arguments->SetReturn(result);
153 } 154 }
154 155
155 } // namespace dart 156 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/error.cc » ('j') | runtime/lib/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698