| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 3918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3929 return Api::NewError("Exception was not re thrown, internal error"); | 3929 return Api::NewError("Exception was not re thrown, internal error"); |
| 3930 } | 3930 } |
| 3931 | 3931 |
| 3932 | 3932 |
| 3933 // --- Native functions --- | 3933 // --- Native functions --- |
| 3934 | 3934 |
| 3935 | 3935 |
| 3936 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 3936 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 3937 int index) { | 3937 int index) { |
| 3938 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3938 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3939 if (index < 0 || index >= arguments->Count()) { | 3939 const int apparent_count = Dart_GetNativeArgumentCount(args); |
| 3940 if ((index < 0) || (index >= apparent_count)) { |
| 3940 return Api::NewError( | 3941 return Api::NewError( |
| 3941 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3942 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3942 CURRENT_FUNC, arguments->Count() - 1, index); | 3943 CURRENT_FUNC, apparent_count - 1, index); |
| 3943 } | 3944 } |
| 3945 // Hide closure object if present. |
| 3946 index += arguments->Count() - apparent_count; |
| 3947 |
| 3944 Isolate* isolate = arguments->isolate(); | 3948 Isolate* isolate = arguments->isolate(); |
| 3945 CHECK_ISOLATE(isolate); | 3949 CHECK_ISOLATE(isolate); |
| 3950 if (index == 0) { |
| 3951 if (arguments->ToInstanceFunction() && arguments->ToClosureFunction()) { |
| 3952 // Retrieve the receiver from the context. |
| 3953 const Context& context = Context::Handle(isolate->top_context()); |
| 3954 return Api::NewHandle(isolate, context.At(0)); |
| 3955 } |
| 3956 } |
| 3946 return Api::NewHandle(isolate, arguments->At(index)); | 3957 return Api::NewHandle(isolate, arguments->At(index)); |
| 3947 } | 3958 } |
| 3948 | 3959 |
| 3949 | 3960 |
| 3950 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 3961 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
| 3951 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3962 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3952 return arguments->Count(); | 3963 int count = arguments->Count(); |
| 3964 // In the instance closure function case, the receiver is accessed from |
| 3965 // the context and the closure at index 0 is hidden, so the apparent |
| 3966 // argument count remains unchanged. |
| 3967 if (arguments->ToClosureFunction() && !arguments->ToInstanceFunction()) { |
| 3968 // The closure at index 0 is hidden and therefore not counted. |
| 3969 count--; |
| 3970 } |
| 3971 return count; |
| 3953 } | 3972 } |
| 3954 | 3973 |
| 3955 | 3974 |
| 3956 // This function has friend access to SetReturnUnsafe. | 3975 // This function has friend access to SetReturnUnsafe. |
| 3957 void SetReturnValueHelper(Dart_NativeArguments args, Dart_Handle retval) { | 3976 void SetReturnValueHelper(Dart_NativeArguments args, Dart_Handle retval) { |
| 3958 NoGCScope no_gc_scope; | 3977 NoGCScope no_gc_scope; |
| 3959 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3978 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3960 arguments->SetReturnUnsafe(Api::UnwrapHandle(retval)); | 3979 arguments->SetReturnUnsafe(Api::UnwrapHandle(retval)); |
| 3961 } | 3980 } |
| 3962 | 3981 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4444 } | 4463 } |
| 4445 { | 4464 { |
| 4446 NoGCScope no_gc; | 4465 NoGCScope no_gc; |
| 4447 RawObject* raw_obj = obj.raw(); | 4466 RawObject* raw_obj = obj.raw(); |
| 4448 isolate->heap()->SetPeer(raw_obj, peer); | 4467 isolate->heap()->SetPeer(raw_obj, peer); |
| 4449 } | 4468 } |
| 4450 return Api::Success(isolate); | 4469 return Api::Success(isolate); |
| 4451 } | 4470 } |
| 4452 | 4471 |
| 4453 } // namespace dart | 4472 } // namespace dart |
| OLD | NEW |