Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
张蕾
Geth-Modification
Commits
5f6f5e34
Unverified
Commit
5f6f5e34
authored
Jun 02, 2020
by
Guillaume Ballet
Committed by
GitHub
Jun 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: handle undefined + null in console funcs (#21160)
parent
d98c42c0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
8 deletions
+58
-8
bridge.go
console/bridge.go
+10
-8
bridge_test.go
console/bridge_test.go
+48
-0
No files found.
console/bridge.go
View file @
5f6f5e34
...
@@ -233,11 +233,12 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
...
@@ -233,11 +233,12 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
if
len
(
call
.
Arguments
)
<
1
{
if
len
(
call
.
Arguments
)
<
1
{
return
nil
,
fmt
.
Errorf
(
"usage: unlockAccount(account, [ password, duration ])"
)
return
nil
,
fmt
.
Errorf
(
"usage: unlockAccount(account, [ password, duration ])"
)
}
}
account
:=
call
.
Argument
(
0
)
// Make sure we have an account specified to unlock.
// Make sure we have an account specified to unlock.
if
call
.
Argument
(
0
)
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
if
goja
.
IsUndefined
(
account
)
||
goja
.
IsNull
(
account
)
||
account
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
return
nil
,
fmt
.
Errorf
(
"first argument must be the account to unlock"
)
return
nil
,
fmt
.
Errorf
(
"first argument must be the account to unlock"
)
}
}
account
:=
call
.
Argument
(
0
)
// If password is not given or is the null value, prompt the user for it.
// If password is not given or is the null value, prompt the user for it.
var
passwd
goja
.
Value
var
passwd
goja
.
Value
...
@@ -285,10 +286,10 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
...
@@ -285,10 +286,10 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
passwd
=
call
.
Argument
(
2
)
passwd
=
call
.
Argument
(
2
)
)
)
if
message
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
if
goja
.
IsUndefined
(
message
)
||
message
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
return
nil
,
fmt
.
Errorf
(
"first argument must be the message to sign"
)
return
nil
,
fmt
.
Errorf
(
"first argument must be the message to sign"
)
}
}
if
account
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
if
goja
.
IsUndefined
(
account
)
||
account
.
ExportType
()
.
Kind
()
!=
reflect
.
String
{
return
nil
,
fmt
.
Errorf
(
"second argument must be the account to sign with"
)
return
nil
,
fmt
.
Errorf
(
"second argument must be the account to sign with"
)
}
}
...
@@ -317,10 +318,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
...
@@ -317,10 +318,11 @@ func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
if
nArgs
:=
len
(
call
.
Arguments
);
nArgs
<
1
{
if
nArgs
:=
len
(
call
.
Arguments
);
nArgs
<
1
{
return
nil
,
fmt
.
Errorf
(
"usage: sleep(<number of seconds>)"
)
return
nil
,
fmt
.
Errorf
(
"usage: sleep(<number of seconds>)"
)
}
}
if
!
isNumber
(
call
.
Argument
(
0
))
{
sleepObj
:=
call
.
Argument
(
0
)
if
goja
.
IsUndefined
(
sleepObj
)
||
goja
.
IsNull
(
sleepObj
)
||
!
isNumber
(
sleepObj
)
{
return
nil
,
fmt
.
Errorf
(
"usage: sleep(<number of seconds>)"
)
return
nil
,
fmt
.
Errorf
(
"usage: sleep(<number of seconds>)"
)
}
}
sleep
:=
call
.
Argument
(
0
)
.
ToFloat
()
sleep
:=
sleepObj
.
ToFloat
()
time
.
Sleep
(
time
.
Duration
(
sleep
*
float64
(
time
.
Second
)))
time
.
Sleep
(
time
.
Duration
(
sleep
*
float64
(
time
.
Second
)))
return
call
.
VM
.
ToValue
(
true
),
nil
return
call
.
VM
.
ToValue
(
true
),
nil
}
}
...
@@ -338,13 +340,13 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
...
@@ -338,13 +340,13 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
return
nil
,
fmt
.
Errorf
(
"usage: sleepBlocks(<n blocks>[, max sleep in seconds])"
)
return
nil
,
fmt
.
Errorf
(
"usage: sleepBlocks(<n blocks>[, max sleep in seconds])"
)
}
}
if
nArgs
>=
1
{
if
nArgs
>=
1
{
if
!
isNumber
(
call
.
Argument
(
0
))
{
if
goja
.
IsNull
(
call
.
Argument
(
0
))
||
goja
.
IsUndefined
(
call
.
Argument
(
0
))
||
!
isNumber
(
call
.
Argument
(
0
))
{
return
nil
,
fmt
.
Errorf
(
"expected number as first argument"
)
return
nil
,
fmt
.
Errorf
(
"expected number as first argument"
)
}
}
blocks
=
call
.
Argument
(
0
)
.
ToInteger
()
blocks
=
call
.
Argument
(
0
)
.
ToInteger
()
}
}
if
nArgs
>=
2
{
if
nArgs
>=
2
{
if
!
isNumber
(
call
.
Argument
(
1
))
{
if
goja
.
IsNull
(
call
.
Argument
(
1
))
||
goja
.
IsUndefined
(
call
.
Argument
(
1
))
||
!
isNumber
(
call
.
Argument
(
1
))
{
return
nil
,
fmt
.
Errorf
(
"expected number as second argument"
)
return
nil
,
fmt
.
Errorf
(
"expected number as second argument"
)
}
}
sleep
=
call
.
Argument
(
1
)
.
ToInteger
()
sleep
=
call
.
Argument
(
1
)
.
ToInteger
()
...
...
console/bridge_test.go
0 → 100644
View file @
5f6f5e34
// Copyright 2020 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
console
import
(
"testing"
"github.com/dop251/goja"
"github.com/ethereum/go-ethereum/internal/jsre"
)
// TestUndefinedAsParam ensures that personal functions can receive
// `undefined` as a parameter.
func
TestUndefinedAsParam
(
t
*
testing
.
T
)
{
b
:=
bridge
{}
call
:=
jsre
.
Call
{}
call
.
Arguments
=
[]
goja
.
Value
{
goja
.
Undefined
()}
b
.
UnlockAccount
(
call
)
b
.
Sign
(
call
)
b
.
Sleep
(
call
)
}
// TestNullAsParam ensures that personal functions can receive
// `null` as a parameter.
func
TestNullAsParam
(
t
*
testing
.
T
)
{
b
:=
bridge
{}
call
:=
jsre
.
Call
{}
call
.
Arguments
=
[]
goja
.
Value
{
goja
.
Null
()}
b
.
UnlockAccount
(
call
)
b
.
Sign
(
call
)
b
.
Sleep
(
call
)
}
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