Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef VM_NATIVE_ENTRY_H_ | 5 #ifndef VM_NATIVE_ENTRY_H_ |
| 6 #define VM_NATIVE_ENTRY_H_ | 6 #define VM_NATIVE_ENTRY_H_ |
| 7 | 7 |
| 8 #include "platform/memory_sanitizer.h" | 8 #include "platform/memory_sanitizer.h" |
| 9 | 9 |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 DEOPTIMIZE_ALOT; \ | 64 DEOPTIMIZE_ALOT; \ |
| 65 } \ | 65 } \ |
| 66 VERIFY_ON_TRANSITION; \ | 66 VERIFY_ON_TRANSITION; \ |
| 67 } \ | 67 } \ |
| 68 static RawObject* DN_Helper##name(Isolate* isolate, \ | 68 static RawObject* DN_Helper##name(Isolate* isolate, \ |
| 69 Thread* thread, \ | 69 Thread* thread, \ |
| 70 Zone* zone, \ | 70 Zone* zone, \ |
| 71 NativeArguments* arguments) | 71 NativeArguments* arguments) |
| 72 | 72 |
| 73 | 73 |
| 74 // Helper that throws an argument exception. | |
| 75 void DartNativeThrowArgumentException(const Instance& instance); | |
| 76 | |
| 74 // Natives should throw an exception if an illegal argument or null is passed. | 77 // Natives should throw an exception if an illegal argument or null is passed. |
| 75 // type name = value. | 78 // type name = value. |
| 76 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ | 79 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ |
| 77 const Instance& __##name##_instance__ = \ | 80 const Instance& __##name##_instance__ = \ |
| 78 Instance::CheckedHandle(zone, value); \ | 81 Instance::CheckedHandle(zone, value); \ |
| 79 if (!__##name##_instance__.Is##type()) { \ | 82 if (!__##name##_instance__.Is##type()) { \ |
| 80 const Array& __args__ = Array::Handle(Array::New(1)); \ | 83 DartNativeThrowArgumentException(__##name##_instance__); \ |
| 81 __args__.SetAt(0, __##name##_instance__); \ | |
| 82 Exceptions::ThrowByType(Exceptions::kArgument, __args__); \ | |
| 83 } \ | 84 } \ |
| 84 const type& name = type::Cast(__##name##_instance__); | 85 const type& name = type::Cast(__##name##_instance__); |
| 85 | 86 |
| 86 | 87 |
| 87 // Natives should throw an exception if an illegal argument is passed. | 88 // Natives should throw an exception if an illegal argument is passed. |
| 88 // type name = value. | 89 // type name = value. |
| 89 #define GET_NATIVE_ARGUMENT(type, name, value) \ | 90 #define GET_NATIVE_ARGUMENT(type, name, value) \ |
| 90 const Instance& __##name##_instance__ = \ | 91 const Instance& __##name##_instance__ = \ |
| 91 Instance::CheckedHandle(zone, value); \ | 92 Instance::CheckedHandle(zone, value); \ |
| 92 type& name = type::Handle(zone); \ | 93 type& name = type::Handle(zone); \ |
| 93 if (!__##name##_instance__.IsNull()) { \ | 94 if (!__##name##_instance__.IsNull()) { \ |
| 94 if (!__##name##_instance__.Is##type()) { \ | 95 if (!__##name##_instance__.Is##type()) { \ |
| 95 const Array& __args__ = Array::Handle(Array::New(1)); \ | 96 DartNativeThrowArgumentException(__##name##_instance__); \ |
| 96 __args__.SetAt(0, __##name##_instance__); \ | |
| 97 Exceptions::ThrowByType(Exceptions::kArgument, __args__); \ | |
| 98 } \ | 97 } \ |
| 99 } \ | 98 } \ |
| 100 name ^= value; | 99 name ^= value; |
|
siva
2016/02/18 16:55:22
Not sure why we did it this way and not as:
const
Cutch
2016/02/18 17:04:41
That doesn't compile without first doing a RawCast
siva
2016/05/27 23:47:24
Got it.
| |
| 101 | 100 |
| 102 | 101 |
| 103 // Helper class for resolving and handling native functions. | 102 // Helper class for resolving and handling native functions. |
| 104 class NativeEntry : public AllStatic { | 103 class NativeEntry : public AllStatic { |
| 105 public: | 104 public: |
| 106 static const intptr_t kNumArguments = 1; | 105 static const intptr_t kNumArguments = 1; |
| 107 static const intptr_t kNumCallWrapperArguments = 2; | 106 static const intptr_t kNumCallWrapperArguments = 2; |
| 108 | 107 |
| 109 // Resolve specified dart native function to the actual native entrypoint. | 108 // Resolve specified dart native function to the actual native entrypoint. |
| 110 static NativeFunction ResolveNative(const Library& library, | 109 static NativeFunction ResolveNative(const Library& library, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 122 static uword LinkNativeCallEntry(); | 121 static uword LinkNativeCallEntry(); |
| 123 static void LinkNativeCall(Dart_NativeArguments args); | 122 static void LinkNativeCall(Dart_NativeArguments args); |
| 124 private: | 123 private: |
| 125 static bool ReturnValueIsError(NativeArguments* arguments); | 124 static bool ReturnValueIsError(NativeArguments* arguments); |
| 126 static void PropagateErrors(NativeArguments* arguments); | 125 static void PropagateErrors(NativeArguments* arguments); |
| 127 }; | 126 }; |
| 128 | 127 |
| 129 } // namespace dart | 128 } // namespace dart |
| 130 | 129 |
| 131 #endif // VM_NATIVE_ENTRY_H_ | 130 #endif // VM_NATIVE_ENTRY_H_ |
| OLD | NEW |