Chromium Code Reviews| 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 const bool is_instance = arguments->AreOfInstanceFunction(); | |
| 3940 const bool is_closure = arguments->AreOfClosureFunction(); | |
| 3941 if (!is_instance && is_closure) { | |
| 3942 index++; // Hide closure object. | |
|
siva
2012/11/07 18:56:32
This seems to suggest that if one passed in an ind
regis
2012/11/08 18:08:30
Good catch! Incrementing the index after the check
| |
| 3943 } | |
| 3939 if (index < 0 || index >= arguments->Count()) { | 3944 if (index < 0 || index >= arguments->Count()) { |
| 3940 return Api::NewError( | 3945 return Api::NewError( |
| 3941 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3946 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 3942 CURRENT_FUNC, arguments->Count() - 1, index); | 3947 CURRENT_FUNC, arguments->Count() - 1, index); |
| 3943 } | 3948 } |
| 3944 Isolate* isolate = arguments->isolate(); | 3949 Isolate* isolate = arguments->isolate(); |
| 3945 CHECK_ISOLATE(isolate); | 3950 CHECK_ISOLATE(isolate); |
| 3946 return Api::NewHandle(isolate, arguments->At(index)); | 3951 if ((index == 0) && is_instance && is_closure) { |
| 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 } else { | |
| 3956 return Api::NewHandle(isolate, arguments->At(index)); | |
| 3957 } | |
| 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 if (arguments->AreOfClosureFunction() && | |
| 3965 !arguments->AreOfInstanceFunction()) { | |
| 3966 // The closure at index 0 is hidden and therefore not counted. | |
| 3967 count--; | |
| 3968 // In the instance closure function case, the receiver is accessed from | |
| 3969 // the context and the closure at index 0 is hidden, so the apparent | |
| 3970 // argument count remains unchanged. | |
|
siva
2012/11/07 18:56:32
This comment should appear outside the if statemen
regis
2012/11/08 18:08:30
Done.
| |
| 3971 } | |
| 3972 return count; | |
| 3953 } | 3973 } |
| 3954 | 3974 |
| 3955 | 3975 |
| 3956 // This function has friend access to SetReturnUnsafe. | 3976 // This function has friend access to SetReturnUnsafe. |
| 3957 void SetReturnValueHelper(Dart_NativeArguments args, Dart_Handle retval) { | 3977 void SetReturnValueHelper(Dart_NativeArguments args, Dart_Handle retval) { |
| 3958 NoGCScope no_gc_scope; | 3978 NoGCScope no_gc_scope; |
| 3959 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3979 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 3960 arguments->SetReturnUnsafe(Api::UnwrapHandle(retval)); | 3980 arguments->SetReturnUnsafe(Api::UnwrapHandle(retval)); |
| 3961 } | 3981 } |
| 3962 | 3982 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4444 } | 4464 } |
| 4445 { | 4465 { |
| 4446 NoGCScope no_gc; | 4466 NoGCScope no_gc; |
| 4447 RawObject* raw_obj = obj.raw(); | 4467 RawObject* raw_obj = obj.raw(); |
| 4448 isolate->heap()->SetPeer(raw_obj, peer); | 4468 isolate->heap()->SetPeer(raw_obj, peer); |
| 4449 } | 4469 } |
| 4450 return Api::Success(isolate); | 4470 return Api::Success(isolate); |
| 4451 } | 4471 } |
| 4452 | 4472 |
| 4453 } // namespace dart | 4473 } // namespace dart |
| OLD | NEW |