Skip to content

Commit 5d4fa87

Browse files
alcuadrados1na
authored andcommitted
Replace Object.assign calls and fix type errors (ethereumjs#529)
* Replace Object.assign calls and fix type errors * Make LoopResult#runState optional again * Fix type error
1 parent c2a5cec commit 5d4fa87

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

lib/evm/eei.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export default class EEI {
467467
}
468468

469469
async _baseCall(msg: Message): Promise<BN> {
470-
const selfdestruct = Object.assign({}, this._result.selfdestruct)
470+
const selfdestruct = { ...this._result.selfdestruct }
471471
msg.selfdestruct = selfdestruct
472472

473473
// empty the return data buffer
@@ -520,7 +520,7 @@ export default class EEI {
520520
* @param {Buffer} data
521521
*/
522522
async create(gasLimit: BN, value: BN, data: Buffer, salt: Buffer | null = null): Promise<BN> {
523-
const selfdestruct = Object.assign({}, this._result.selfdestruct)
523+
const selfdestruct = { ...this._result.selfdestruct }
524524
const msg = new Message({
525525
caller: this._env.address,
526526
gasLimit: gasLimit,

lib/evm/interpreter.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export default class Interpreter {
231231
) {
232232
result.gasUsed = totalGas
233233
} else {
234-
Object.assign(result, OOGResult(message.gasLimit))
234+
result = { ...result, ...OOGResult(message.gasLimit) }
235235
}
236236

237237
// Save code if a new contract was created
@@ -276,22 +276,28 @@ export default class Interpreter {
276276
gasUsed = message.gasLimit
277277
}
278278

279-
// remove any logs on error
280-
result = Object.assign({}, result, {
279+
// Clear the result on error
280+
result = {
281+
...result,
281282
logs: [],
282-
gasRefund: null,
283-
selfdestruct: null,
284-
})
283+
gasRefund: new BN(0),
284+
selfdestruct: {},
285+
}
285286
}
286287

287-
return Object.assign({}, result, {
288-
runState: Object.assign({}, loopRes.runState, result, eei._env),
288+
return {
289+
...result,
290+
runState: {
291+
...loopRes.runState!,
292+
...result,
293+
...eei._env,
294+
},
289295
exception: loopRes.exception,
290296
exceptionError: loopRes.exceptionError,
291297
gas: eei._gasLeft,
292298
gasUsed,
293299
return: result.returnValue ? result.returnValue : Buffer.alloc(0),
294-
})
300+
}
295301
}
296302

297303
/**

lib/evm/loop.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ export default class Loop {
6262
}
6363

6464
async run(code: Buffer, opts: RunOpts = {}): Promise<LoopResult> {
65-
Object.assign(this._runState, {
66-
code: code,
67-
programCounter: opts.pc || this._runState.programCounter,
68-
validJumps: this._getValidJumpDests(code),
69-
})
65+
this._runState.code = code
66+
this._runState.programCounter = opts.pc || this._runState.programCounter
67+
this._runState.validJumps = this._getValidJumpDests(code)
7068

7169
// Check that the programCounter is in range
7270
const pc = this._runState.programCounter

tests/GeneralStateTestsRunner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function parseTestCases (forkConfig, testData, data, gasLimit, value) {
1111
if (testData['post'][forkConfig]) {
1212
testCases = testData['post'][forkConfig].map(testCase => {
1313
let testIndexes = testCase['indexes']
14-
let tx = Object.assign({}, testData.transaction)
14+
let tx = { ...testData.transaction }
1515
if (data !== undefined && testIndexes['data'] !== data) {
1616
return null
1717
}

0 commit comments

Comments
 (0)