Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Chromium
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
Chromium
Commits
2f8f5881
Commit
2f8f5881
authored
Jan 05, 2023
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add nativeBox unittest.
parent
a90da11d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
51 deletions
+57
-51
bindings.gni
third_party/blink/renderer/bindings/bindings.gni
+5
-4
nativeBox.cc
third_party/blink/renderer/bindings/core/v8/nativeBox.cc
+39
-47
nativeBox_unittest.cc
...rty/blink/renderer/bindings/core/v8/nativeBox_unittest.cc
+13
-0
No files found.
third_party/blink/renderer/bindings/bindings.gni
View file @
2f8f5881
...
...
@@ -146,10 +146,10 @@ 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",
"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",
...
...
@@ -228,6 +228,7 @@ bindings_unittest_files = get_path_info(
"core/v8/script_wrappable_v8_gc_integration_test.cc",
"core/v8/to_v8_test.cc",
"core/v8/to_v8_traits_test.cc",
"core/v8/nativeBox_unittest.cc",
"core/v8/trace_wrapper_v8_reference_test.cc",
"core/v8/v8_binding_for_testing.cc",
"core/v8/v8_binding_for_testing.h",
...
...
third_party/blink/renderer/bindings/core/v8/nativeBox.cc
View file @
2f8f5881
...
...
@@ -9,6 +9,7 @@
#include "v8/include/v8-typed-array.h"
#include "v8/include/v8-value.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-maybe.h"
using
std
::
vector
;
...
...
@@ -19,72 +20,63 @@ using v8::Uint32;
using
v8
::
Object
;
using
v8
::
Local
;
namespace
L
=
Loadable
;
#if 0
// Anonymous which contains all transform functions
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
)
{
// Find out an anatomy of LoadableModule
// and spawn correspond JSObject which is equivalent to
// LoadableModule in aspect of interfaces.
Local<Object> obj =
Local<Object>(
);
Local
<
Object
>
obj
=
v8
::
Object
::
New
(
isolate
);
if
(
!
native
)
{
// No LoadableModule found
// return null Handle<JSObject> .
return
obj
;
return
Local
<
Object
>
()
;
}
// 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;
vector
<
Loadable
::
IFaceSpec
>
IFSpecs
=
native
->
specs
();
Local
<
v8
::
Context
>
context
=
isolate
->
GetCurrentContext
();
for
(
auto
&
iface
:
IFSpecs
)
{
// Wrap native codes with an extra Transform layer.
//
// Transform layer provide functionality of transforming
// between v8 types and native types.
vector
<
Loadable
::
ArgType
>
args
=
iface
.
getArgs
();
V8_Builtin
nativeWitTrans
=
wrapWithTransformLayer
(
iface
.
getCallback
(),
args
,
iface
.
getRet
());
// Attach V8_Builtin to Object which defined at the first line of
// this procedure.
Local
<
Value
>
functionName
=
v8
::
String
::
NewFromUtf8
(
isolate
,
iface
.
getName
().
c_str
()).
ToLocalChecked
();
Local
<
Value
>
jsFunction
=
v8
::
FunctionTemplate
::
New
(
isolate
,
nativeWitTrans
)
->
GetFunction
(
context
).
ToLocalChecked
();
v8
::
Maybe
<
bool
>
ret
=
obj
->
Set
(
context
,
functionName
,
jsFunction
);
if
(
ret
.
IsJust
())
{
return
Local
<
Object
>
();
}
};
}
return
obj
;
}
#endif
third_party/blink/renderer/bindings/core/v8/nativeBox_unittest.cc
0 → 100644
View file @
2f8f5881
#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
)
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment