Commit 2f8f5881 authored by Linshizhi's avatar Linshizhi

Add nativeBox unittest.

parent a90da11d
...@@ -146,10 +146,10 @@ blink_core_sources_bindings = ...@@ -146,10 +146,10 @@ blink_core_sources_bindings =
"core/v8/v8_idle_task_runner.h", "core/v8/v8_idle_task_runner.h",
"core/v8/v8_initializer.cc", "core/v8/v8_initializer.cc",
"core/v8/v8_initializer.h", "core/v8/v8_initializer.h",
#"core/v8/v8_initializer_custom.cc", "core/v8/v8_initializer_custom.cc",
#"core/v8/v8_initializer_custom.h", "core/v8/v8_initializer_custom.h",
#"core/v8/nativeBox.h", "core/v8/nativeBox.h",
#"core/v8/nativeBox.cc", "core/v8/nativeBox.cc",
"extensions/loadablemodule/src/Loadable.cc", "extensions/loadablemodule/src/Loadable.cc",
"extensions/loadablemodule/src/Loadable.h", "extensions/loadablemodule/src/Loadable.h",
"core/v8/v8_intersection_observer_delegate.cc", "core/v8/v8_intersection_observer_delegate.cc",
...@@ -228,6 +228,7 @@ bindings_unittest_files = get_path_info( ...@@ -228,6 +228,7 @@ bindings_unittest_files = get_path_info(
"core/v8/script_wrappable_v8_gc_integration_test.cc", "core/v8/script_wrappable_v8_gc_integration_test.cc",
"core/v8/to_v8_test.cc", "core/v8/to_v8_test.cc",
"core/v8/to_v8_traits_test.cc", "core/v8/to_v8_traits_test.cc",
"core/v8/nativeBox_unittest.cc",
"core/v8/trace_wrapper_v8_reference_test.cc", "core/v8/trace_wrapper_v8_reference_test.cc",
"core/v8/v8_binding_for_testing.cc", "core/v8/v8_binding_for_testing.cc",
"core/v8/v8_binding_for_testing.h", "core/v8/v8_binding_for_testing.h",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "v8/include/v8-typed-array.h" #include "v8/include/v8-typed-array.h"
#include "v8/include/v8-value.h" #include "v8/include/v8-value.h"
#include "v8/include/v8-object.h" #include "v8/include/v8-object.h"
#include "v8/include/v8-maybe.h"
using std::vector; using std::vector;
...@@ -19,72 +20,63 @@ using v8::Uint32; ...@@ -19,72 +20,63 @@ using v8::Uint32;
using v8::Object; using v8::Object;
using v8::Local; using v8::Local;
namespace L = Loadable;
#if 0
// Anonymous which contains all transform functions // Anonymous which contains all transform functions
namespace { namespace {
typedef void (*V8_Builtin)(const v8::FunctionCallbackInfo<v8::Value>& args);
V8_Builtin wrapWithTransformLayer(Loadable::Callback callback,
vector<Loadable::ArgType> &argInfo,
Loadable::ArgType retInfo) {
auto f = [](const v8::FunctionCallbackInfo<v8::Value> &args) -> void {
};
return f;
} }
NativeBox::NativeBox(L::LoadableModule *module): native(module) {}
}
NativeBox::NativeBox(Loadable::LoadableModule *module): native(module) {}
Local<Object> NativeBox::ToObject(v8::Isolate *isolate) { Local<Object> NativeBox::ToObject(v8::Isolate *isolate) {
// Find out an anatomy of LoadableModule // Find out an anatomy of LoadableModule
// and spawn correspond JSObject which is equivalent to // and spawn correspond JSObject which is equivalent to
// LoadableModule in aspect of interfaces. // LoadableModule in aspect of interfaces.
Local<Object> obj = Local<Object>(); Local<Object> obj = v8::Object::New(isolate);
if (!native) { if (!native) {
// No LoadableModule found // No LoadableModule found
// return null Handle<JSObject> . // return null Handle<JSObject> .
return obj; return Local<Object>();
} }
// Analyze LoadableModule // Analyze LoadableModule
vector<L::IFaceSpec> IFSpecs = native->specs(); vector<Loadable::IFaceSpec> IFSpecs = native->specs();
Local<v8::Context> context = isolate->GetCurrentContext();
for (vector<L::IFaceSpec>::iterator iter = IFSpecs.begin();
iter < IFSpecs.end(); ++iter) { for (auto &iface: IFSpecs) {
// Wrap native codes with an extra Transform layer.
// Get return type //
L::ArgType retType = iter->getRet(); // Transform layer provide functionality of transforming
// between v8 types and native types.
// Get type of arguments vector<Loadable::ArgType> args = iface.getArgs();
std::vector<L::ArgType> args = iter->getArgs(); V8_Builtin nativeWitTrans = wrapWithTransformLayer(
iface.getCallback(), args, iface.getRet());
void *callback = iter->getCallback(); // Attach V8_Builtin to Object which defined at the first line of
// this procedure.
// Spawn correspond method and attach the method to Local<Value> functionName = v8::String::NewFromUtf8(
// spawned JSObj. isolate, iface.getName().c_str()).ToLocalChecked();
auto transform_layer = [&](const v8::FunctionCallbackInfo<v8::Value>& args_) -> void { Local<Value> jsFunction = v8::FunctionTemplate::New(isolate, nativeWitTrans)
->GetFunction(context).ToLocalChecked();
if (args.size() != args_.Length()) return; v8::Maybe<bool> ret = obj->Set(context, functionName, jsFunction);
if (ret.IsJust()) {
int i = 0; return Local<Object>();
// 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; return obj;
} }
#endif
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/extensions/loadablemodule/src/Loadable.h"
#include "third_party/blink/renderer/bindings/core/v8/nativeBox.h"
namespace blink{
TEST(NativeBoxTest, Transform) {
}
}
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