• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deno-web3 / solc / 13575745341

27 Feb 2025 08:59PM UTC coverage: 76.21% (+4.4%) from 71.786%
13575745341

Pull #3

github

web-flow
Merge ba97409cf into 3d76b77ea
Pull Request #3: Update with upstream

4 of 8 branches covered (50.0%)

Branch coverage included in aggregate %.

159 of 214 new or added lines in 7 files covered. (74.3%)

185 of 240 relevant lines covered (77.08%)

2.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.29
/bindings/core.ts
1
import type { Alloc, CoreBindings, License, Reset, SolJson } from 'solc/types'
2
import { bindSolcMethod, bindSolcMethodWithFallbackFunc } from './helpers.ts'
1✔
3

4
export function setupCore(solJson: SolJson): CoreBindings {
1✔
5
  const core = {
2✔
6
    alloc: bindAlloc(solJson),
2✔
7
    license: bindLicense(solJson),
2✔
8
    version: bindVersion<() => string>(solJson),
2✔
9
    reset: bindReset(solJson),
2✔
10
  }
2✔
11

12
  const helpers = {
2✔
13
    // @ts-expect-error binding to this
14
    addFunction: unboundAddFunction.bind(this, solJson),
2✔
15
    // @ts-expect-error binding to this
16
    removeFunction: unboundRemoveFunction.bind(this, solJson),
2✔
17
    // @ts-expect-error binding to this
18
    copyFromCString: unboundCopyFromCString.bind(this, solJson),
2✔
19
    // @ts-expect-error binding to this
20
    copyToCString: unboundCopyToCString.bind(this, solJson, core.alloc),
2✔
21
  }
2✔
22

23
  return {
2✔
24
    ...core,
2✔
25
    ...helpers,
2✔
26
  }
2✔
27
}
2✔
28

29
/**********************
30
 * Core Functions
31
 **********************/
32

33
/**
34
 * Returns a binding to the solidity_alloc function.
35
 *
36
 * @param solJson The Emscripten compiled Solidity object.
37
 */
38
function bindAlloc(solJson: SolJson) {
1✔
39
  const allocBinding = bindSolcMethod<Alloc>(
2✔
40
    solJson,
2✔
41
    'solidity_alloc',
2✔
42
    'number',
2✔
43
    ['number'],
6✔
44
    null,
2✔
45
  )
46

47
  return allocBinding
2✔
48
}
2✔
49

50
/**
51
 * Returns a binding to the solidity_version method.
52
 *
53
 * @param solJson The Emscripten compiled Solidity object.
54
 */
55
function bindVersion<T>(solJson: SolJson) {
1✔
56
  return bindSolcMethodWithFallbackFunc<T>(
2✔
57
    solJson,
2✔
58
    'solidity_version',
2✔
59
    'string',
2✔
60
    [],
2✔
61
    'version',
2✔
62
  )
63
}
2✔
64

65
/**
66
 * Returns a binding to the solidity_license method.
67
 *
68
 * If the current solJson version < 0.4.14 then this will bind an empty function.
69
 *
70
 * @param solJson The Emscripten compiled Solidity object.
71
 */
72
function bindLicense(solJson: SolJson) {
1✔
NEW
73
  return bindSolcMethodWithFallbackFunc<License>(
×
NEW
74
    solJson,
×
NEW
75
    'solidity_license',
×
NEW
76
    'string',
×
NEW
77
    [],
×
NEW
78
    'license',
×
NEW
79
    () => {
×
NEW
80
    },
×
81
  )
82
}
2✔
83

84
/**
85
 * Returns a binding to the solidity_reset method.
86
 *
87
 * @param solJson The Emscripten compiled Solidity object.
88
 */
89
function bindReset(solJson: SolJson) {
1✔
90
  return bindSolcMethod<Reset>(
2✔
91
    solJson,
2✔
92
    'solidity_reset',
2✔
93
    null,
2✔
94
    [],
2✔
95
    null,
2✔
96
  )
97
}
2✔
98

99
/**********************
100
 * Helpers Functions
101
 **********************/
102

103
/**
104
 * Copy to a C string.
105
 *
106
 * Allocates memory using solc's allocator.
107
 *
108
 * Before 0.6.0:
109
 *   Assuming copyToCString is only used in the context of wrapCallback, solc will free these pointers.
110
 *   See https://github.com/ethereum/solidity/blob/v0.5.13/libsolc/libsolc.h#L37-L40
111
 *
112
 * After 0.6.0:
113
 *   The duty is on solc-js to free these pointers. We accomplish that by calling `reset` at the end.
114
 *
115
 * @param solJson The Emscripten compiled Solidity object.
116
 * @param alloc The memory allocation function.
117
 * @param str The source string being copied to a C string.
118
 * @param ptr The pointer location where the C string will be set.
119
 */
NEW
120
function unboundCopyToCString(solJson: SolJson, alloc: Alloc, str: string, ptr: number) {
×
NEW
121
  const length = solJson.lengthBytesUTF8(str)
×
122

NEW
123
  const buffer = alloc(length + 1)
×
124

NEW
125
  solJson.stringToUTF8(str, buffer, length + 1)
×
NEW
126
  solJson.setValue(ptr, buffer, '*')
×
127

NEW
128
  return str
×
NEW
129
}
×
130

131
/**
132
 * Wrapper over Emscripten's C String copying function (which can be different
133
 * on different versions).
134
 *
135
 * @param solJson The Emscripten compiled Solidity object.
136
 * @param ptr The pointer location where the C string will be referenced.
137
 */
NEW
138
function unboundCopyFromCString(solJson: SolJson, ptr: number) {
×
NEW
139
  return solJson.UTF8ToString(ptr)
×
NEW
140
}
×
141

142
function unboundAddFunction(solJson: SolJson, func: (...args: unknown[]) => unknown, signature?: string) {
2✔
143
  return solJson.addFunction(func, signature)
2✔
144
}
2✔
145

146
function unboundRemoveFunction(solJson: SolJson, ptr: number) {
2✔
147
  return solJson.removeFunction(ptr)
2✔
148
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc