Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
37c7e817
Commit
37c7e817
authored
Jun 09, 2016
by
Dave Hoover
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Smoke testing compiler.compile and discovering some simplifications
parent
e8d34daa
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
33 deletions
+59
-33
app.js
src/app.js
+6
-1
compiler.js
src/app/compiler.js
+10
-17
editor.js
src/app/editor.js
+18
-10
execution-context.js
src/app/execution-context.js
+6
-1
renderer.js
src/app/renderer.js
+2
-4
compiler-test.js
test/compiler-test.js
+16
-0
index.js
test/index.js
+1
-0
No files found.
src/app.js
View file @
37c7e817
...
...
@@ -10,7 +10,9 @@ var gistHandler = new GistHandler();
var
StorageHandler
=
require
(
'./app/storage-handler'
);
var
Editor
=
require
(
'./app/editor'
);
var
Renderer
=
require
(
'./app/renderer'
);
var
Compiler
=
require
(
'./app/compiler'
);
var
ExecutionContext
=
require
(
'./app/execution-context'
);
// The event listener needs to be registered as early as possible, because the
// parent will send the message upon the "load" event.
...
...
@@ -423,7 +425,10 @@ var run = function () {
return
$
.
getJSON
(
'https://api.github.com/repos/'
+
root
+
'/contents/'
+
path
,
cb
);
}
var
compiler
=
new
Compiler
(
editor
,
handleGithubCall
,
$
(
'#output'
),
getHidingRHP
,
updateFiles
);
var
executionContext
=
new
ExecutionContext
();
var
renderer
=
new
Renderer
(
editor
,
executionContext
,
updateFiles
);
var
compiler
=
new
Compiler
(
editor
,
renderer
,
queryParams
,
handleGithubCall
,
$
(
'#output'
),
getHidingRHP
,
updateFiles
);
executionContext
.
setCompiler
(
compiler
);
function
setVersionText
(
text
)
{
$
(
'#version'
).
text
(
text
);
...
...
src/app/compiler.js
View file @
37c7e817
var
webworkify
=
require
(
'webworkify'
);
var
QueryParams
=
require
(
'./query-params'
);
var
utils
=
require
(
'./utils'
);
var
Renderer
=
require
(
'./renderer'
);
var
Base64
=
require
(
'js-base64'
).
Base64
;
function
Compiler
(
editor
,
handleGithubCall
,
outputField
,
hidingRHP
,
updateFiles
)
{
var
renderer
=
new
Renderer
(
editor
,
this
,
updateFiles
);
var
queryParams
=
new
QueryParams
();
function
Compiler
(
editor
,
renderer
,
queryParams
,
handleGithubCall
,
outputField
,
hidingRHP
,
updateFiles
)
{
var
compileJSON
;
var
compilerAcceptsMultipleFiles
;
var
previousInput
=
''
;
var
sourceAnnotations
=
[];
var
cachedRemoteFiles
=
{};
var
worker
=
null
;
...
...
@@ -40,7 +34,6 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
var
compile
=
function
(
missingInputs
)
{
editor
.
clearAnnotations
();
sourceAnnotations
=
[];
outputField
.
empty
();
var
input
=
editor
.
getValue
();
editor
.
setCacheFileContent
(
input
);
...
...
@@ -59,10 +52,10 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
};
this
.
compile
=
compile
;
this
.
addAnnotation
=
function
(
annotation
)
{
sourceAnnotations
[
sourceAnnotations
.
length
]
=
annotation
;
editor
.
setAnnotations
(
sourceAnnotations
);
};
function
setCompileJSON
(
_compileJSON
)
{
compileJSON
=
_compileJSON
;
}
this
.
setCompileJSON
=
setCompileJSON
;
// this is exposed for testing
function
onCompilerLoaded
(
setVersionText
,
version
)
{
setVersionText
(
version
);
...
...
@@ -92,14 +85,14 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
compilerAcceptsMultipleFiles
=
false
;
compile
=
Module
.
cwrap
(
'compileJSON'
,
'string'
,
[
'string'
,
'number'
]);
}
compileJSON
=
function
(
source
,
optimize
,
cb
)
{
setCompileJSON
(
function
(
source
,
optimize
,
cb
)
{
try
{
var
result
=
compile
(
source
,
optimize
);
}
catch
(
exception
)
{
result
=
JSON
.
stringify
({
error
:
'Uncaught JavaScript exception:
\
n'
+
exception
});
}
compilationFinished
(
result
,
missingInputs
);
};
}
)
;
onCompilerLoaded
(
setVersionText
,
Module
.
cwrap
(
'version'
,
'string'
,
[])());
}
}
...
...
@@ -150,7 +143,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
function
loadInternal
(
url
,
setVersionText
)
{
delete
window
.
Module
;
// Set a safe fallback until the new one is loaded
compileJSON
=
function
(
source
,
optimize
)
{
compilationFinished
(
'{}'
);
}
;
setCompileJSON
(
function
(
source
,
optimize
)
{
compilationFinished
(
'{}'
);
})
;
var
newScript
=
document
.
createElement
(
'script'
);
newScript
.
type
=
'text/javascript'
;
...
...
@@ -184,9 +177,9 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
});
worker
.
onerror
=
function
(
msg
)
{
console
.
log
(
msg
.
data
);
};
worker
.
addEventListener
(
'error'
,
function
(
msg
)
{
console
.
log
(
msg
.
data
);
});
compileJSON
=
function
(
source
,
optimize
)
{
setCompileJSON
(
function
(
source
,
optimize
)
{
worker
.
postMessage
({
cmd
:
'compile'
,
source
:
source
,
optimize
:
optimize
});
};
}
)
;
worker
.
postMessage
({
cmd
:
'loadVersion'
,
data
:
url
});
}
...
...
src/app/editor.js
View file @
37c7e817
...
...
@@ -6,6 +6,15 @@ var ace = require('brace');
require
(
'../mode-solidity.js'
);
function
Editor
(
loadingFromGist
)
{
var
SOL_CACHE_UNTITLED
=
utils
.
getCacheFilePrefix
()
+
'Untitled'
;
var
SOL_CACHE_FILE
=
null
;
var
editor
=
ace
.
edit
(
'input'
);
var
sessions
=
{};
var
sourceAnnotations
=
[];
setupStuff
(
getFiles
());
this
.
newFile
=
function
()
{
var
untitledCount
=
''
;
while
(
window
.
localStorage
[
SOL_CACHE_UNTITLED
+
untitledCount
])
{
...
...
@@ -58,7 +67,7 @@ function Editor (loadingFromGist) {
return
this
.
getFiles
().
indexOf
(
utils
.
fileKey
(
name
))
!==
-
1
;
};
this
.
getFiles
=
function
()
{
function
getFiles
()
{
var
files
=
[];
for
(
var
f
in
window
.
localStorage
)
{
if
(
f
.
indexOf
(
utils
.
getCacheFilePrefix
(),
0
)
===
0
)
{
...
...
@@ -67,7 +76,8 @@ function Editor (loadingFromGist) {
}
}
return
files
;
};
}
this
.
getFiles
=
getFiles
;
this
.
packageFiles
=
function
()
{
var
files
=
{};
...
...
@@ -100,9 +110,15 @@ function Editor (loadingFromGist) {
};
this
.
clearAnnotations
=
function
()
{
sourceAnnotations
=
[];
editor
.
getSession
().
clearAnnotations
();
};
this
.
addAnnotation
=
function
(
annotation
)
{
sourceAnnotations
[
sourceAnnotations
.
length
]
=
annotation
;
this
.
setAnnotations
(
sourceAnnotations
);
};
this
.
setAnnotations
=
function
(
sourceAnnotations
)
{
editor
.
getSession
().
setAnnotations
(
sourceAnnotations
);
};
...
...
@@ -152,14 +168,6 @@ function Editor (loadingFromGist) {
editor
.
setSession
(
sessions
[
SOL_CACHE_FILE
]);
editor
.
resize
(
true
);
}
var
SOL_CACHE_UNTITLED
=
utils
.
getCacheFilePrefix
()
+
'Untitled'
;
var
SOL_CACHE_FILE
=
null
;
var
editor
=
ace
.
edit
(
'input'
);
var
sessions
=
{};
setupStuff
(
this
.
getFiles
());
}
module
.
exports
=
Editor
;
src/app/execution-context.js
View file @
37c7e817
...
...
@@ -13,9 +13,14 @@ if (typeof window.web3 !== 'undefined') {
web3
=
new
Web3
(
new
Web3
.
providers
.
HttpProvider
(
'http://localhost:8545'
));
}
function
ExecutionContext
(
compiler
)
{
function
ExecutionContext
()
{
var
compiler
;
var
executionContext
=
injectedProvider
?
'injected'
:
'vm'
;
this
.
setCompiler
=
function
(
_compiler
)
{
compiler
=
_compiler
;
};
this
.
isVM
=
function
()
{
return
executionContext
===
'vm'
;
};
...
...
src/app/renderer.js
View file @
37c7e817
...
...
@@ -3,11 +3,9 @@ var $ = require('jquery');
var
UniversalDApp
=
require
(
'../universal-dapp.js'
);
var
utils
=
require
(
'./utils'
);
var
ExecutionContext
=
require
(
'./execution-context'
);
function
Renderer
(
editor
,
compiler
,
updateFiles
)
{
function
Renderer
(
editor
,
executionContext
,
updateFiles
)
{
var
detailsOpen
=
{};
var
executionContext
=
new
ExecutionContext
(
compiler
);
function
renderError
(
message
)
{
var
type
=
utils
.
errortype
(
message
);
...
...
@@ -20,7 +18,7 @@ function Renderer (editor, compiler, updateFiles) {
var
errLine
=
parseInt
(
err
[
2
],
10
)
-
1
;
var
errCol
=
err
[
4
]
?
parseInt
(
err
[
4
],
10
)
:
0
;
if
(
errFile
===
''
||
errFile
===
utils
.
fileNameFromKey
(
editor
.
getCacheFile
()))
{
compile
r
.
addAnnotation
({
edito
r
.
addAnnotation
({
row
:
errLine
,
column
:
errCol
,
text
:
message
,
...
...
test/compiler-test.js
0 → 100644
View file @
37c7e817
var
test
=
require
(
'tape'
);
var
Compiler
=
require
(
'../src/app/compiler'
);
test
(
'compiler.compile smoke'
,
function
(
t
)
{
t
.
plan
(
1
);
var
noop
=
function
()
{};
var
fakeEditor
=
{
onChangeSetup
:
noop
,
clearAnnotations
:
noop
,
getValue
:
noop
,
setCacheFileContent
:
noop
,
getCacheFile
:
noop
};
var
fakeOutputField
=
{
empty
:
noop
};
var
fakeQueryParams
=
{
get
:
function
()
{
return
{};
}};
var
compiler
=
new
Compiler
(
fakeEditor
,
null
,
fakeQueryParams
,
null
,
fakeOutputField
);
compiler
.
setCompileJSON
(
noop
);
compiler
.
compile
();
t
.
ok
(
compiler
);
});
test/index.js
View file @
37c7e817
require
(
'./compiler-test'
);
require
(
'./gist-handler-test'
);
require
(
'./query-params-test'
);
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