Skip to content

Commit

Permalink
fix: fix window_or_worker_global_scope.cc build error
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Dec 13, 2024
1 parent 1e4925f commit a2811be
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
24 changes: 23 additions & 1 deletion bridge/core/executing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ExecutingContext* ExecutingContext::From(JSContext* ctx) {
}

#elif WEBF_V8_JS_ENGINE
ExecutingContext* From(v8::Isolate* isolate) {
ExecutingContext* ExecutingContext::From(v8::Isolate* isolate) {
// TODO support
return nullptr;
}
Expand Down Expand Up @@ -522,6 +522,28 @@ static void DispatchPromiseRejectionEvent(const AtomicString& event_type,
}

#elif WEBF_V8_JS_ENGINE
//v8::Local<v8::Value> Global() {
//}

v8::Isolate* ExecutingContext::ctx() {
/* TODO
assert(IsCtxValid());
return script_state_.ctx();
*/
return nullptr;
}

bool ExecutingContext::HandleException(v8::Local<v8::Value> exc) {
return false;
}

void ExecutingContext::ReportError(v8::Local<v8::Value> error) {

}

void ExecutingContext::DefineGlobalProperty(const char* prop, v8::Local<v8::Value> value) {

}

#endif

Expand Down
16 changes: 12 additions & 4 deletions bridge/core/page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ WebFPage::WebFPage(DartIsolateContext* dart_isolate_context,
[](ExecutingContext* context, const char* message) {
WEBF_LOG(ERROR) << message << std::endl;
if (context->IsContextValid()) {
/*TODO support dartMethodPtr
context->dartMethodPtr()->onJSError(context->isDedicated(), context->contextId(), message);
*/
}
},
this);
Expand Down Expand Up @@ -132,6 +134,7 @@ void WebFPage::evaluateScript(const char* script, size_t length, const char* url
context_->EvaluateJavaScript(script, length, url, startLine);
}

#if WEBF_QUICKJS_JS_ENGINE
uint8_t* WebFPage::dumpByteCode(const char* script, size_t length, const char* url, uint64_t* byteLength) {
if (!context_->IsContextValid())
return nullptr;
Expand All @@ -143,6 +146,7 @@ bool WebFPage::evaluateByteCode(uint8_t* bytes, size_t byteLength) {
return false;
return context_->EvaluateByteCode(bytes, byteLength);
}
#endif

std::thread::id WebFPage::currentThread() const {
return ownerThreadId;
Expand Down Expand Up @@ -192,6 +196,7 @@ void WebFPage::EvaluateScriptsInternal(void* page_,
persistent_handle, result_callback, is_success);
}

#if WEBF_QUICKJS_JS_ENGINE
static void ReturnEvaluateQuickjsByteCodeResultToDart(Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback,
bool is_success) {
Expand All @@ -209,15 +214,16 @@ void WebFPage::EvaluateQuickjsByteCodeInternal(void* page_,
auto page = reinterpret_cast<webf::WebFPage*>(page_);
assert(std::this_thread::get_id() == page->currentThread());

// TODO page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id);
page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id);

bool is_success = page->evaluateByteCode(bytes, byteLen);

// TODO page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id);
page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id);

page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateQuickjsByteCodeResultToDart,
persistent_handle, result_callback, is_success);
}
#endif

static void ReturnParseHTMLToDart(Dart_PersistentHandle persistent_handle, ParseHTMLCallback result_callback) {
Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle);
Expand Down Expand Up @@ -281,6 +287,7 @@ static void ReturnDumpByteCodeResultToDart(Dart_Handle persistent_handle, DumpQu
Dart_DeletePersistentHandle_DL(persistent_handle);
}

#if WEBF_QUICKJS_JS_ENGINE
void WebFPage::DumpQuickJsByteCodeInternal(void* page_,
int64_t profile_id,
const char* code,
Expand All @@ -293,16 +300,17 @@ void WebFPage::DumpQuickJsByteCodeInternal(void* page_,
auto page = reinterpret_cast<webf::WebFPage*>(page_);
auto dart_isolate_context = page->executingContext()->dartIsolateContext();

// TODO dart_isolate_context->profiler()->StartTrackEvaluation(profile_id);
dart_isolate_context->profiler()->StartTrackEvaluation(profile_id);

assert(std::this_thread::get_id() == page->currentThread());
uint8_t* bytes = page->dumpByteCode(code, code_len, url, bytecode_len);
*parsed_bytecodes = bytes;

// TODO dart_isolate_context->profiler()->FinishTrackEvaluation(profile_id);
dart_isolate_context->profiler()->FinishTrackEvaluation(profile_id);

dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnDumpByteCodeResultToDart, persistent_handle,
result_callback);
}
#endif

} // namespace webf
8 changes: 6 additions & 2 deletions bridge/core/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ class WebFPage final {
Dart_Handle dart_handle,
EvaluateScriptsCallback result_callback);

#if WEBF_QUICKJS_JS_ENGINE
static void EvaluateQuickjsByteCodeInternal(void* page_,
uint8_t* bytes,
int32_t byteLen,
int64_t profile_id,
Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback);
#endif
static void ParseHTMLInternal(void* page_,
char* code,
int32_t length,
Expand All @@ -76,7 +78,7 @@ class WebFPage final {
void* extra,
Dart_Handle dart_handle,
InvokeModuleEventCallback result_callback);

#if WEBF_QUICKJS_JS_ENGINE
static void DumpQuickJsByteCodeInternal(void* page_,
int64_t profile_id,
const char* code,
Expand All @@ -86,6 +88,7 @@ class WebFPage final {
const char* url,
Dart_PersistentHandle persistent_handle,
DumpQuickjsByteCodeCallback result_callback);
#endif

// evaluate JavaScript source codes in standard mode.
bool evaluateScript(const char* script,
Expand All @@ -96,9 +99,10 @@ class WebFPage final {
int startLine);
bool parseHTML(const char* code, size_t length);
void evaluateScript(const char* script, size_t length, const char* url, int startLine);
#if WEBF_QUICKJS_JS_ENGINE
uint8_t* dumpByteCode(const char* script, size_t length, const char* url, uint64_t* byteLength);
bool evaluateByteCode(uint8_t* bytes, size_t byteLength);

#endif
std::thread::id currentThread() const;

[[nodiscard]] ExecutingContext* executingContext() const { return context_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ const WrapperTypeInfo& ${className}::wrapper_type_info_ = V8${className}::wrappe
}
case TemplateKind.globalFunction: {
object = object as FunctionObject;
options.globalFunctionInstallList.push(` {"${object.declare.name}", ${object.declare.name}, ${object.declare.args.length}}`);
options.globalFunctionInstallList.push(` {"${object.declare.name}", ${object.declare.name}}`);
return _.template(readTemplate('global_function'))({
className,
blob: blob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "<%= blob.filename %>.h"
#include <v8/v8-function-callback.h>
//#include "foundation/native_value_converter.h"
#include "binding_call_methods.h"
#include "bindings/v8/member_installer.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ void V8<%= className %>::InstallGlobalFunctions(ExecutingContext* context) {
std::initializer_list<MemberInstaller::FunctionConfig> functionConfig {
<%= globalFunctionInstallList.join(',\n') %>
};
MemberInstaller::InstallFunctions(context, context->Global(), functionConfig);
MemberInstaller::InstallFunctions(context, functionConfig);
}
<% } %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
static JSValue ${object.declare.name}(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
static void ${object.declare.name}(const v8::FunctionCallbackInfo <v8::Value> &args) {
<%= generateFunctionBody(blob, object.declare) %>
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ JSValue QJS<%= className %>::ConstructorCallback(JSContext* ctx, JSValue func_ob
<% if (overloadMethods[method.name] && overloadMethods[method.name].length > 1) { %>
<% _.forEach(overloadMethods[method.name], function(overloadMethod, index) { %>
static JSValue <%= overloadMethod.name %>_overload_<%= index %>(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
static void <%= overloadMethod.name %>_overload_<%= index %>(const v8::FunctionCallbackInfo <v8::Value> &args) {
<%= generateFunctionBody(blob, overloadMethod, {isInstanceMethod: true}) %>
}
<% }); %>
static JSValue <%= method.name %>(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
static void <%= method.name %>(const v8::FunctionCallbackInfo <v8::Value> &args) {
<%= generateOverLoadSwitchBody(overloadMethods[method.name]) %>
}
<% } else if (method.returnTypeMode && method.returnTypeMode.staticMethod) { %>
static JSValue <%= method.name %>(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
static void <%= method.name %>(const v8::FunctionCallbackInfo <v8::Value> &args) {
<%= generateFunctionBody(blob, method, {isInstanceMethod: false}) %>
}
<% } else { %>
static JSValue <%= method.name %>(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv) {
static void <%= method.name %>(const v8::FunctionCallbackInfo <v8::Value> &args) {
<%= generateFunctionBody(blob, method, {isInstanceMethod: true}) %>
}
<% } %>
Expand Down

0 comments on commit a2811be

Please sign in to comment.