good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
12805c73
Commit
12805c73
authored
Aug 17, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Plain Diff
Merge pull request #1667 from fjl/pretty-printer-improvements
jsre: pretty printer improvements
parents
f6367548
1086e2f2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
jsre/jsre.go
+1
-0
1 addition, 0 deletions
jsre/jsre.go
jsre/pretty.go
+17
-6
17 additions, 6 deletions
jsre/pretty.go
with
18 additions
and
6 deletions
jsre/jsre.go
+
1
−
0
View file @
12805c73
...
...
@@ -66,6 +66,7 @@ func New(assetPath string) *JSRE {
re
.
loopWg
.
Add
(
1
)
go
re
.
runEventLoop
()
re
.
Set
(
"loadScript"
,
re
.
loadScript
)
re
.
Set
(
"inspect"
,
prettyPrintJS
)
return
re
}
...
...
This diff is collapsed.
Click to expand it.
jsre/pretty.go
+
17
−
6
View file @
12805c73
...
...
@@ -51,7 +51,15 @@ var boringKeys = map[string]bool{
// prettyPrint writes value to standard output.
func
prettyPrint
(
vm
*
otto
.
Otto
,
value
otto
.
Value
)
{
ppctx
{
vm
}
.
printValue
(
value
,
0
)
ppctx
{
vm
}
.
printValue
(
value
,
0
,
false
)
}
func
prettyPrintJS
(
call
otto
.
FunctionCall
)
otto
.
Value
{
for
_
,
v
:=
range
call
.
ArgumentList
{
prettyPrint
(
call
.
Otto
,
v
)
fmt
.
Println
()
}
return
otto
.
UndefinedValue
()
}
type
ppctx
struct
{
vm
*
otto
.
Otto
}
...
...
@@ -60,10 +68,10 @@ func (ctx ppctx) indent(level int) string {
return
strings
.
Repeat
(
indentString
,
level
)
}
func
(
ctx
ppctx
)
printValue
(
v
otto
.
Value
,
level
int
)
{
func
(
ctx
ppctx
)
printValue
(
v
otto
.
Value
,
level
int
,
inArray
bool
)
{
switch
{
case
v
.
IsObject
()
:
ctx
.
printObject
(
v
.
Object
(),
level
)
ctx
.
printObject
(
v
.
Object
(),
level
,
inArray
)
case
v
.
IsNull
()
:
specialColor
.
Print
(
"null"
)
case
v
.
IsUndefined
()
:
...
...
@@ -84,7 +92,7 @@ func (ctx ppctx) printValue(v otto.Value, level int) {
}
}
func
(
ctx
ppctx
)
printObject
(
obj
*
otto
.
Object
,
level
int
)
{
func
(
ctx
ppctx
)
printObject
(
obj
*
otto
.
Object
,
level
int
,
inArray
bool
)
{
switch
obj
.
Class
()
{
case
"Array"
:
lv
,
_
:=
obj
.
Get
(
"length"
)
...
...
@@ -101,7 +109,7 @@ func (ctx ppctx) printObject(obj *otto.Object, level int) {
for
i
:=
int64
(
0
);
i
<
len
;
i
++
{
el
,
err
:=
obj
.
Get
(
strconv
.
FormatInt
(
i
,
10
))
if
err
==
nil
{
ctx
.
printValue
(
el
,
level
+
1
)
ctx
.
printValue
(
el
,
level
+
1
,
true
)
}
if
i
<
len
-
1
{
fmt
.
Printf
(
", "
)
...
...
@@ -129,12 +137,15 @@ func (ctx ppctx) printObject(obj *otto.Object, level int) {
for
i
,
k
:=
range
keys
{
v
,
_
:=
obj
.
Get
(
k
)
fmt
.
Printf
(
"%s%s: "
,
ctx
.
indent
(
level
+
1
),
k
)
ctx
.
printValue
(
v
,
level
+
1
)
ctx
.
printValue
(
v
,
level
+
1
,
false
)
if
i
<
len
(
keys
)
-
1
{
fmt
.
Printf
(
","
)
}
fmt
.
Println
()
}
if
inArray
{
level
--
}
fmt
.
Printf
(
"%s}"
,
ctx
.
indent
(
level
))
case
"Function"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment