OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_ARGUMENTS_H_ | 5 #ifndef V8_ARGUMENTS_H_ |
6 #define V8_ARGUMENTS_H_ | 6 #define V8_ARGUMENTS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 // Object* Runtime_function(Arguments args) { | 22 // Object* Runtime_function(Arguments args) { |
23 // ... use args[i] here ... | 23 // ... use args[i] here ... |
24 // } | 24 // } |
25 // | 25 // |
26 // Note that length_ (whose value is in the integer range) is defined | 26 // Note that length_ (whose value is in the integer range) is defined |
27 // as intptr_t to provide endian-neutrality on 64-bit archs. | 27 // as intptr_t to provide endian-neutrality on 64-bit archs. |
28 | 28 |
29 class Arguments BASE_EMBEDDED { | 29 class Arguments BASE_EMBEDDED { |
30 public: | 30 public: |
31 Arguments(int length, Object** arguments) | 31 Arguments(int length, Object** arguments) |
32 : length_(length), arguments_(arguments) { } | 32 : length_(length), arguments_(arguments) { |
| 33 DCHECK_GE(length_, 0); |
| 34 } |
33 | 35 |
34 Object*& operator[] (int index) { | 36 Object*& operator[] (int index) { |
35 DCHECK(0 <= index && index < length_); | 37 DCHECK_GE(index, 0); |
| 38 DCHECK_LT(static_cast<uint32_t>(index), static_cast<uint32_t>(length_)); |
36 return *(reinterpret_cast<Object**>(reinterpret_cast<intptr_t>(arguments_) - | 39 return *(reinterpret_cast<Object**>(reinterpret_cast<intptr_t>(arguments_) - |
37 index * kPointerSize)); | 40 index * kPointerSize)); |
38 } | 41 } |
39 | 42 |
40 template <class S> Handle<S> at(int index) { | 43 template <class S> Handle<S> at(int index) { |
41 Object** value = &((*this)[index]); | 44 Object** value = &((*this)[index]); |
42 // This cast checks that the object we're accessing does indeed have the | 45 // This cast checks that the object we're accessing does indeed have the |
43 // expected type. | 46 // expected type. |
44 S::cast(*value); | 47 S::cast(*value); |
45 return Handle<S>(reinterpret_cast<S**>(value)); | 48 return Handle<S>(reinterpret_cast<S**>(value)); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 283 |
281 | 284 |
282 #define RUNTIME_FUNCTION(Name) RUNTIME_FUNCTION_RETURNS_TYPE(Object*, Name) | 285 #define RUNTIME_FUNCTION(Name) RUNTIME_FUNCTION_RETURNS_TYPE(Object*, Name) |
283 #define RUNTIME_FUNCTION_RETURN_PAIR(Name) \ | 286 #define RUNTIME_FUNCTION_RETURN_PAIR(Name) \ |
284 RUNTIME_FUNCTION_RETURNS_TYPE(ObjectPair, Name) | 287 RUNTIME_FUNCTION_RETURNS_TYPE(ObjectPair, Name) |
285 | 288 |
286 } // namespace internal | 289 } // namespace internal |
287 } // namespace v8 | 290 } // namespace v8 |
288 | 291 |
289 #endif // V8_ARGUMENTS_H_ | 292 #endif // V8_ARGUMENTS_H_ |
OLD | NEW |