Skip to content

Commit 812d9a2

Browse files
authored
Merge pull request #411 from ethereum/callback-context
Support callback context in 0.6.x
2 parents 980275c + af7451e commit 812d9a2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

wrapper.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ function setupMethods (soljson) {
1717
return translate.versionToSemver(version());
1818
};
1919

20+
var isVersion6 = semver.gt(versionToSemver(), '0.5.99');
21+
2022
var license;
2123
if ('_solidity_license' in soljson) {
2224
license = soljson.cwrap('solidity_license', 'string', []);
@@ -51,7 +53,7 @@ function setupMethods (soljson) {
5153

5254
var wrapCallbackWithKind = function (callback) {
5355
assert(typeof callback === 'function', 'Invalid callback specified.');
54-
return function (kind, data, contents, error) {
56+
return function (context, kind, data, contents, error) {
5557
var result = callback(soljson.Pointer_stringify(kind), soljson.Pointer_stringify(data));
5658
if (typeof result.contents === 'string') {
5759
copyString(result.contents, contents);
@@ -80,7 +82,7 @@ function setupMethods (soljson) {
8082
}
8183

8284
var singleCallback;
83-
if (semver.gt(versionToSemver(), '0.5.99')) {
85+
if (isVersion6) {
8486
// After 0.6.x multiple kind of callbacks are supported.
8587
var smtSolverCallback = callbacks.smtSolver;
8688
if (smtSolverCallback === undefined) {
@@ -115,6 +117,10 @@ function setupMethods (soljson) {
115117
var output;
116118
try {
117119
args.push(cb);
120+
if (isVersion6) {
121+
// Callback context.
122+
args.push(null);
123+
}
118124
output = compile.apply(undefined, args);
119125
} catch (e) {
120126
removeFunction(cb);
@@ -126,16 +132,19 @@ function setupMethods (soljson) {
126132

127133
var compileJSON = null;
128134
if ('_compileJSON' in soljson) {
135+
// input (text), optimize (bool) -> output (jsontext)
129136
compileJSON = soljson.cwrap('compileJSON', 'string', ['string', 'number']);
130137
}
131138

132139
var compileJSONMulti = null;
133140
if ('_compileJSONMulti' in soljson) {
141+
// input (jsontext), optimize (bool) -> output (jsontext)
134142
compileJSONMulti = soljson.cwrap('compileJSONMulti', 'string', ['string', 'number']);
135143
}
136144

137145
var compileJSONCallback = null;
138146
if ('_compileJSONCallback' in soljson) {
147+
// input (jsontext), optimize (bool), callback (ptr) -> output (jsontext)
139148
var compileInternal = soljson.cwrap('compileJSONCallback', 'string', ['string', 'number', 'number']);
140149
compileJSONCallback = function (input, optimize, readCallback) {
141150
return runWithCallbacks(readCallback, compileInternal, [ input, optimize ]);
@@ -144,13 +153,21 @@ function setupMethods (soljson) {
144153

145154
var compileStandard = null;
146155
if ('_compileStandard' in soljson) {
156+
// input (jsontext), callback (ptr) -> output (jsontext)
147157
var compileStandardInternal = soljson.cwrap('compileStandard', 'string', ['string', 'number']);
148158
compileStandard = function (input, readCallback) {
149159
return runWithCallbacks(readCallback, compileStandardInternal, [ input ]);
150160
};
151161
}
152162
if ('_solidity_compile' in soljson) {
153-
var solidityCompile = soljson.cwrap('solidity_compile', 'string', ['string', 'number']);
163+
var solidityCompile;
164+
if (isVersion6) {
165+
// input (jsontext), callback (ptr), callback_context (ptr) -> output (jsontext)
166+
solidityCompile = soljson.cwrap('solidity_compile', 'string', ['string', 'number', 'number']);
167+
} else {
168+
// input (jsontext), callback (ptr) -> output (jsontext)
169+
solidityCompile = soljson.cwrap('solidity_compile', 'string', ['string', 'number']);
170+
}
154171
compileStandard = function (input, callbacks) {
155172
return runWithCallbacks(callbacks, solidityCompile, [ input ]);
156173
};

0 commit comments

Comments
 (0)