-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1013 from NativeScript/tdermendzhiev/functions-ov…
…erloading feat: Add support for methods with same name and different parameters
- Loading branch information
Showing
42 changed files
with
1,240 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// CFunctionWrapper.h | ||
// NativeScript | ||
// | ||
// Created by Yavor Georgiev on 07.07.14. | ||
// Copyright (c) 2014 г. Telerik. All rights reserved. | ||
// | ||
|
||
#ifndef __NativeScript__CFunctionWrapper__ | ||
#define __NativeScript__CFunctionWrapper__ | ||
|
||
#include "FFICall.h" | ||
#include "FunctionWrapper.h" | ||
|
||
namespace NativeScript { | ||
|
||
class CFunctionCall : public FFICall { | ||
|
||
public: | ||
CFunctionCall(FunctionWrapper* owner, void* functionPointer, bool retainsReturnedCocoaObjects) | ||
: FFICall(owner) | ||
, _functionPointer(functionPointer) | ||
, _retainsReturnedCocoaObjects(retainsReturnedCocoaObjects) { | ||
} | ||
|
||
DECLARE_INFO; | ||
|
||
template <typename CellType> | ||
static JSC::IsoSubspace* subspaceFor(JSC::VM& vm) { | ||
return &vm.tnsCFunctionWrapperSpace; | ||
} | ||
|
||
void* functionPointer() const { | ||
return this->_functionPointer; | ||
} | ||
bool retainsReturnedCocoaObjects() const { | ||
return this->_retainsReturnedCocoaObjects; | ||
} | ||
|
||
private: | ||
void* _functionPointer; | ||
|
||
bool _retainsReturnedCocoaObjects; | ||
}; | ||
|
||
class CFunctionWrapper : public FunctionWrapper { | ||
public: | ||
typedef FunctionWrapper Base; | ||
|
||
static CFunctionWrapper* create(JSC::VM& vm, JSC::Structure* structure, void* functionPointer, const WTF::String& name, JSC::JSCell* returnType, const WTF::Vector<JSC::JSCell*>& parameterTypes, bool retainsReturnedCocoaObjects) { | ||
CFunctionWrapper* function = new (NotNull, JSC::allocateCell<CFunctionWrapper>(vm.heap)) CFunctionWrapper(vm, structure); | ||
function->finishCreation(vm, functionPointer, name, returnType, parameterTypes, retainsReturnedCocoaObjects); | ||
return function; | ||
} | ||
|
||
DECLARE_INFO; | ||
|
||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) { | ||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info()); | ||
} | ||
|
||
void* functionPointer() { | ||
return static_cast<CFunctionCall*>(this->onlyFuncInContainer())->functionPointer(); | ||
} | ||
|
||
private: | ||
CFunctionWrapper(JSC::VM& vm, JSC::Structure* structure) | ||
: Base(vm, structure) { | ||
} | ||
|
||
void finishCreation(JSC::VM&, void* functionPointer, const WTF::String& name, JSC::JSCell* returnType, const WTF::Vector<JSC::JSCell*>& parameterTypes, bool retainsReturnedCocoaObjects); | ||
|
||
static void destroy(JSC::JSCell* cell) { | ||
static_cast<CFunctionWrapper*>(cell)->~CFunctionWrapper(); | ||
} | ||
|
||
static void preInvocation(FFICall*, JSC::ExecState*, FFICall::Invocation&); | ||
static void postInvocation(FFICall*, JSC::ExecState*, FFICall::Invocation&); | ||
}; | ||
} // namespace NativeScript | ||
|
||
#endif /* defined(__NativeScript__CFunctionWrapper__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// CFunctionWrapper.cpp | ||
// NativeScript | ||
// | ||
// Created by Yavor Georgiev on 07.07.14. | ||
// Copyright (c) 2014 г. Telerik. All rights reserved. | ||
// | ||
|
||
#include "CFunctionWrapper.h" | ||
|
||
namespace NativeScript { | ||
using namespace JSC; | ||
|
||
const ClassInfo CFunctionWrapper::s_info = { "CFunctionWrapper", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(CFunctionWrapper) }; | ||
|
||
void CFunctionWrapper::finishCreation(VM& vm, void* functionPointer, const WTF::String& name, JSCell* returnType, const WTF::Vector<JSCell*>& parameterTypes, bool retainsReturnedCocoaObjects) { | ||
Base::finishCreation(vm, name); | ||
auto call = std::make_unique<CFunctionCall>(this, functionPointer, retainsReturnedCocoaObjects); | ||
call->initializeFFI(vm, { &preInvocation, &postInvocation }, returnType, parameterTypes); | ||
this->_functionsContainer.push_back(std::move(call)); | ||
Base::initializeFunctionWrapper(vm, parameterTypes.size()); | ||
} | ||
|
||
void CFunctionWrapper::preInvocation(FFICall* callee, ExecState*, FFICall::Invocation& invocation) { | ||
invocation.function = const_cast<void*>(static_cast<CFunctionCall*>(callee)->functionPointer()); | ||
} | ||
|
||
void CFunctionWrapper::postInvocation(FFICall* callee, ExecState*, FFICall::Invocation& invocation) { | ||
CFunctionCall* call = static_cast<CFunctionCall*>(callee); | ||
if (call->retainsReturnedCocoaObjects()) { | ||
[invocation.getResult<id>() release]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.