Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
4c05a1f1
Commit
4c05a1f1
authored
Jan 02, 2019
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 runtime 的性能,加入 Long 函数到runtime
parent
04454590
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
const.go
plugin/dapp/js/executor/const.go
+0
-0
js.go
plugin/dapp/js/executor/js.go
+8
-2
jsvm_test.go
plugin/dapp/js/executor/jsvm_test.go
+15
-1
No files found.
plugin/dapp/js/executor/const.go
View file @
4c05a1f1
This diff is collapsed.
Click to expand it.
plugin/dapp/js/executor/js.go
View file @
4c05a1f1
...
...
@@ -12,10 +12,16 @@ import (
)
var
driverName
=
ptypes
.
JsX
var
basevm
*
otto
.
Otto
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
js
{}))
basevm
=
otto
.
New
()
_
,
err
:=
basevm
.
Run
(
callcode
)
if
err
!=
nil
{
panic
(
err
)
}
}
//Init 插件初始化
...
...
@@ -78,7 +84,7 @@ func (u *js) callVM(prefix string, payload *jsproto.Call, tx *types.Transaction,
}
vm
.
Set
(
"args"
,
payload
.
Args
)
callfunc
:=
"callcode(context, f, args, loglist)"
jsvalue
,
err
:=
vm
.
Run
(
callcode
+
string
(
code
)
+
"
\n
"
+
callfunc
)
jsvalue
,
err
:=
vm
.
Run
(
string
(
code
)
+
"
\n
"
+
callfunc
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -195,7 +201,7 @@ func (u *js) createVM(name string, tx *types.Transaction, index int) (*otto.Otto
if
err
!=
nil
{
return
nil
,
err
}
vm
:=
otto
.
New
()
vm
:=
basevm
.
Copy
()
vm
.
Set
(
"context"
,
string
(
data
))
u
.
getstatedbFunc
(
vm
,
name
)
u
.
getlocaldbFunc
(
vm
,
name
)
...
...
plugin/dapp/js/executor/jsvm_test.go
View file @
4c05a1f1
...
...
@@ -69,7 +69,7 @@ Query.prototype.hello = function(args) {
}
`
func
initExec
(
ldb
db
.
DB
,
kvdb
db
.
KVDB
,
t
*
testing
.
T
)
*
js
{
func
initExec
(
ldb
db
.
DB
,
kvdb
db
.
KVDB
,
t
assert
.
Testing
T
)
*
js
{
e
:=
newjs
()
.
(
*
js
)
e
.
SetEnv
(
1
,
time
.
Now
()
.
Unix
(),
1
)
e
.
SetLocalDB
(
kvdb
)
...
...
@@ -190,6 +190,20 @@ func TestBigInt(t *testing.T) {
assert
.
Equal
(
t
,
`{"balance":"9223372036854775807","balance1":"-9223372036854775808","balance2":9007199254740990,"balance3":-9007199254740990}`
,
string
(
kvs
[
0
]
.
Value
))
}
func
BenchmarkBigInt
(
b
*
testing
.
B
)
{
dir
,
ldb
,
kvdb
:=
util
.
CreateTestDB
()
defer
util
.
CloseTestDB
(
dir
,
ldb
)
e
:=
initExec
(
ldb
,
kvdb
,
b
)
//test call error(invalid json input)
s
:=
fmt
.
Sprintf
(
`{"balance":%d,"balance1":%d,"balance2":%d,"balance3":%d}`
,
math
.
MaxInt64
,
math
.
MinInt64
,
9007199254740990
,
-
9007199254740990
)
call
,
tx
:=
callCodeTx
(
"test"
,
"hello"
,
s
)
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
_
,
err
:=
e
.
callVM
(
"exec"
,
call
,
tx
,
0
,
nil
)
assert
.
Nil
(
b
,
err
)
}
}
func
TestRewriteJSON
(
t
*
testing
.
T
)
{
s
:=
fmt
.
Sprintf
(
`{"balance":%d,"balance1":%d,"balance2":%d,"balance3":%d}`
,
math
.
MaxInt64
,
math
.
MinInt64
,
9007199254740990
,
-
9007199254740990
)
quota
:=
fmt
.
Sprintf
(
`{"balance":"%d","balance1":"%d","balance2":%d,"balance3":%d}`
,
math
.
MaxInt64
,
math
.
MinInt64
,
9007199254740990
,
-
9007199254740990
)
...
...
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