-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
497 additions
and
161 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
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
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
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,63 @@ | ||
/* | ||
* Copyright (C) 2022-present The WebF authors. All rights reserved. | ||
*/ | ||
|
||
#ifndef WEBF_CORE_NATIVE_NATIVE_FUNCTION_H_ | ||
#define WEBF_CORE_NATIVE_NATIVE_FUNCTION_H_ | ||
|
||
#include "foundation/casting.h" | ||
#include "foundation/function.h" | ||
#include "foundation/native_value.h" | ||
#include "plugin_api/rust_readable.h" | ||
|
||
namespace webf { | ||
|
||
class SharedExceptionState; | ||
typedef struct WebFNativeFunctionContext WebFNativeFunctionContext; | ||
|
||
using WebFNativeFunctionCallback = void (*)(WebFNativeFunctionContext* callback_context, | ||
int32_t argc, | ||
NativeValue* argv, | ||
SharedExceptionState* shared_exception_state); | ||
using WebFNativeFunctionFreePtrFn = void (*)(WebFNativeFunctionContext* callback_context); | ||
|
||
struct WebFNativeFunctionContext : public RustReadable { | ||
WebFNativeFunctionCallback callback; | ||
WebFNativeFunctionFreePtrFn free_ptr; | ||
void* ptr; | ||
}; | ||
|
||
class WebFNativeFunction : public Function { | ||
public: | ||
WebFNativeFunction(WebFNativeFunctionContext* callback_context, SharedExceptionState* shared_exception_state) | ||
: callback_context_(callback_context), shared_exception_state_(shared_exception_state) {} | ||
|
||
static const std::shared_ptr<WebFNativeFunction> Create(WebFNativeFunctionContext* callback_context, | ||
SharedExceptionState* shared_exception_state) { | ||
return std::make_shared<WebFNativeFunction>(callback_context, shared_exception_state); | ||
} | ||
|
||
~WebFNativeFunction() { | ||
callback_context_->free_ptr(callback_context_); | ||
delete callback_context_; | ||
} | ||
|
||
bool IsWebFNativeFunction() const override { return true; } | ||
|
||
void Invoke(ExecutingContext* context, int32_t argc, NativeValue* argv) { | ||
callback_context_->callback(callback_context_, argc, argv, shared_exception_state_); | ||
} | ||
|
||
private: | ||
WebFNativeFunctionContext* callback_context_; | ||
SharedExceptionState* shared_exception_state_; | ||
}; | ||
|
||
template <> | ||
struct DowncastTraits<WebFNativeFunction> { | ||
static bool AllowFrom(const Function& function) { return function.IsWebFNativeFunction(); } | ||
}; | ||
|
||
} // namespace webf | ||
|
||
#endif // WEBF_CORE_NATIVE_NATIVE_FUNCTION_H_ |
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,19 @@ | ||
/* | ||
* Copyright (C) 2019-2022 The Kraken authors. All rights reserved. | ||
* Copyright (C) 2022-present The WebF authors. All rights reserved. | ||
*/ | ||
|
||
#ifndef BRIDGE_FOUNDATION_FUNCTION_H_ | ||
#define BRIDGE_FOUNDATION_FUNCTION_H_ | ||
|
||
namespace webf { | ||
|
||
class Function { | ||
public: | ||
virtual bool IsQJSFunction() const { return false; } | ||
virtual bool IsWebFNativeFunction() const { return false; } | ||
}; | ||
|
||
} // namespace webf | ||
|
||
#endif // BRIDGE_FOUNDATION_FUNCTION_H_ |
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.