Commit a90da11d authored by Linshizhi's avatar Linshizhi

Stage: Uniform Interface for service codes.

parent 6aaad925
[submodule "third_party/blink/renderer/bindings/extensions/loadablemodule"]
path = third_party/blink/renderer/bindings/extensions/loadablemodule
url = git@gitlab.laihua.com:linshizhi/loadablemodule.git
......@@ -146,6 +146,12 @@ blink_core_sources_bindings =
"core/v8/v8_idle_task_runner.h",
"core/v8/v8_initializer.cc",
"core/v8/v8_initializer.h",
#"core/v8/v8_initializer_custom.cc",
#"core/v8/v8_initializer_custom.h",
#"core/v8/nativeBox.h",
#"core/v8/nativeBox.cc",
"extensions/loadablemodule/src/Loadable.cc",
"extensions/loadablemodule/src/Loadable.h",
"core/v8/v8_intersection_observer_delegate.cc",
"core/v8/v8_intersection_observer_delegate.h",
"core/v8/v8_iterator_result_value.cc",
......
......@@ -43,6 +43,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_for_context_dispose.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_html_document.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_initializer_custom.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_page_popup_controller_binding.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_window.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
......@@ -213,6 +214,8 @@ void LocalWindowProxy::Initialize() {
if (World().IsMainWorld()) {
GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
}
// PostInitializeV8(GetIsolate());
}
void LocalWindowProxy::CreateContext() {
......
#include "nativeBox.h"
#include <string>
#include <vector>
#include "third_party/blink/renderer/bindings/extensions/loadablemodule/src/Loadable.h"
#include "v8/include/v8.h"
#include "v8/include/v8-primitive.h"
#include "v8/include/v8-typed-array.h"
#include "v8/include/v8-value.h"
#include "v8/include/v8-object.h"
using std::vector;
using v8::TypedArray;
using v8::String;
using v8::Value;
using v8::Uint32;
using v8::Object;
using v8::Local;
namespace L = Loadable;
#if 0
// Anonymous which contains all transform functions
namespace {
}
NativeBox::NativeBox(L::LoadableModule *module): native(module) {}
Local<Object> NativeBox::ToObject(v8::Isolate *isolate) {
// Find out an anatomy of LoadableModule
// and spawn correspond JSObject which is equivalent to
// LoadableModule in aspect of interfaces.
Local<Object> obj = Local<Object>();
if (!native) {
// No LoadableModule found
// return null Handle<JSObject> .
return obj;
}
// Analyze LoadableModule
vector<L::IFaceSpec> IFSpecs = native->specs();
for (vector<L::IFaceSpec>::iterator iter = IFSpecs.begin();
iter < IFSpecs.end(); ++iter) {
// Get return type
L::ArgType retType = iter->getRet();
// Get type of arguments
std::vector<L::ArgType> args = iter->getArgs();
void *callback = iter->getCallback();
// Spawn correspond method and attach the method to
// spawned JSObj.
auto transform_layer = [&](const v8::FunctionCallbackInfo<v8::Value>& args_) -> void {
if (args.size() != args_.Length()) return;
int i = 0;
// Transform argument into native.
for (std::vector<L::ArgType>::iterator iter = args.begin();
iter < args.end(); ++iter) {
switch (*iter) {
case L::ARG_TYPE_NUM:
transformToNative<uint32_t>(args[i]);
break;
case L::ARG_TYPE_STR:
transformToNative<std::string>(args[i]);
break;
case L::ARG_TYPE_ARRAY:
transformToNative<uint8_t*>(args[i]);
break;
}
++i;
}
};
}
return obj;
}
#endif
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-value.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-local-handle.h"
#include "third_party/blink/renderer/bindings/extensions/loadablemodule/src/Loadable.h"
namespace L = Loadable;
class NativeBox {
public:
NativeBox() = delete;
NativeBox(L::LoadableModule *module);
v8::Local<v8::Object> ToObject(v8::Isolate *isolate);
private:
L::LoadableModule *native;
};
#include <string>
#include <iostream>
#include "nativeBox.h"
#include "v8/include/v8.h"
#include "v8/include/v8-template.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
#include "third_party/blink/renderer/bindings/extensions/loadablemodule/src/Loadable.h"
#include <dlfcn.h>
using v8::Local;
using v8::ObjectTemplate;
using v8::Context;
using v8::Object;
using v8::Value;
using v8::Maybe;
using v8::String;
static void LoadeModule(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1) return;;
v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
Local<Value> arg = args[0];
String::Utf8Value moduleName(isolate, arg);
void *symbols = dlopen("liblms.so", RTLD_LAZY);
if (!symbols) {
std::cout << "No Module found" << std::endl;
return;
}
Loadable::LoadableModule *(*load)(std::string);
load = (Loadable::LoadableModule*(*)(std::string))dlsym(symbols, "load");
Loadable::LoadableModule *module = load("MP4Encoder");
NativeBox box {module};
args.GetReturnValue().Set(box.ToObject(isolate));
}
void PostInitializeV8(v8::Isolate* isolate) {
Local<Context> context = isolate->GetCurrentContext();
Local<Object> global = context->Global();
Local<Value> callbackName =
v8::String::NewFromUtf8(isolate, "LoadModule").ToLocalChecked();
Local<Value> callback =
v8::FunctionTemplate::New(isolate, LoadeModule)
->GetFunction(context).ToLocalChecked();
Maybe<bool> ret = global->Set(context, callbackName, callback);
ret.IsJust();
}
#include "v8/include/v8.h"
#ifndef V8_INITIALIZER_CUSTOM_H
#define V8_INITIALIZER_CUSTOM_H
void PostInitializeV8(v8::Isolate* isolate);
void PostInitializeV8_Context(v8::Isolate *isolate, v8::Local<v8::Context> context);
#endif /* V8_INITIALIZER_CUSTOM_H */
Subproject commit 0a966f95cb3603cc87723cec4a6ebd5f15da06e5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment