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