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
310f7516
Unverified
Commit
310f7516
authored
May 19, 2022
by
Eduard S
Committed by
GitHub
May 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/tracers/js: add memory.length method (#24887)
parent
a35a5cad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
0 deletions
+12
-0
goja.go
eth/tracers/js/goja.go
+5
-0
tracer.go
eth/tracers/js/tracer.go
+4
-0
tracer_test.go
eth/tracers/js/tracer_test.go
+3
-0
No files found.
eth/tracers/js/goja.go
View file @
310f7516
...
...
@@ -517,10 +517,15 @@ func (mo *memoryObj) GetUint(addr int64) goja.Value {
return
res
}
func
(
mo
*
memoryObj
)
Length
()
int
{
return
mo
.
w
.
memory
.
Len
()
}
func
(
m
*
memoryObj
)
setupObject
()
*
goja
.
Object
{
o
:=
m
.
vm
.
NewObject
()
o
.
Set
(
"slice"
,
m
.
vm
.
ToValue
(
m
.
Slice
))
o
.
Set
(
"getUint"
,
m
.
vm
.
ToValue
(
m
.
GetUint
))
o
.
Set
(
"length"
,
m
.
vm
.
ToValue
(
m
.
Length
))
return
o
}
...
...
eth/tracers/js/tracer.go
View file @
310f7516
...
...
@@ -148,6 +148,10 @@ func (mw *memoryWrapper) getUint(addr int64) *big.Int {
func
(
mw
*
memoryWrapper
)
pushObject
(
vm
*
duktape
.
Context
)
{
obj
:=
vm
.
PushObject
()
// Generate the `length` method which returns the memory length
vm
.
PushGoFunction
(
func
(
ctx
*
duktape
.
Context
)
int
{
ctx
.
PushInt
(
mw
.
memory
.
Len
());
return
1
})
vm
.
PutPropString
(
obj
,
"length"
)
// Generate the `slice` method which takes two ints and returns a buffer
vm
.
PushGoFunction
(
func
(
ctx
*
duktape
.
Context
)
int
{
blob
:=
mw
.
slice
(
int64
(
ctx
.
GetInt
(
-
2
)),
int64
(
ctx
.
GetInt
(
-
1
)))
...
...
eth/tracers/js/tracer_test.go
View file @
310f7516
...
...
@@ -125,6 +125,9 @@ func testTracer(t *testing.T, newTracer tracerCtor) {
},
{
// tests that depth is reported correctly
code
:
"{depths: [], step: function(log) { this.depths.push(log.stack.length()); }, fault: function() {}, result: function() { return this.depths; }}"
,
want
:
`[0,1,2]`
,
},
{
// tests memory length
code
:
"{lengths: [], step: function(log) { this.lengths.push(log.memory.length()); }, fault: function() {}, result: function() { return this.lengths; }}"
,
want
:
`[0,0,0]`
,
},
{
// tests to-string of opcodes
code
:
"{opcodes: [], step: function(log) { this.opcodes.push(log.op.toString()); }, fault: function() {}, result: function() { return this.opcodes; }}"
,
want
:
`["PUSH1","PUSH1","STOP"]`
,
...
...
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