mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
Fix the offset for the source map positions. #6
This commit is contained in:
parent
dd9eb4b049
commit
47430b3bc0
@ -207,21 +207,27 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
if( size == 0 ) {
|
||||
return;
|
||||
}
|
||||
SourceMapWriter sourceMap = createSourceMap ? new SourceMapWriter() : null;
|
||||
|
||||
int start = wasm.size();
|
||||
WasmOutputStream stream = new WasmOutputStream();
|
||||
stream.writeVaruint32( size );
|
||||
for( Function func : functions.values() ) {
|
||||
if( sourceMap != null && func.sourceMappings != null ) {
|
||||
for( SourceMapping mapping : func.sourceMappings ) {
|
||||
mapping.addOffset( wasm.size() );
|
||||
sourceMap.addMapping( mapping );
|
||||
}
|
||||
}
|
||||
func.addCodeOffset( start + stream.size() );
|
||||
func.functionsStream.writeTo( stream );
|
||||
}
|
||||
wasm.writeSection( SectionType.Code, stream );
|
||||
|
||||
SourceMapWriter sourceMap = createSourceMap ? new SourceMapWriter() : null;
|
||||
if( sourceMap != null ) {
|
||||
int offset = wasm.size() - start - stream.size();
|
||||
for( Function func : functions.values() ) {
|
||||
if( func.sourceMappings != null ) {
|
||||
func.addCodeOffset( offset );
|
||||
for( SourceMapping mapping : func.sourceMappings ) {
|
||||
sourceMap.addMapping( mapping );
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceMap.generate( target.getSourceMapOutput() );
|
||||
}
|
||||
}
|
||||
@ -461,6 +467,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
WasmOutputStream functionsStream = function.functionsStream = new WasmOutputStream();
|
||||
functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 );
|
||||
localsStream.writeTo( functionsStream );
|
||||
function.addCodeOffset( functionsStream.size() );
|
||||
codeStream.writeTo( functionsStream );
|
||||
functionsStream.write( END );
|
||||
}
|
||||
|
@ -62,4 +62,18 @@ class Function extends SectionEntry {
|
||||
}
|
||||
sourceMappings.add( new SourceMapping( streamPosition, javaSourceLine, sourceFileName ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an offset to the marked code position in the source map
|
||||
*
|
||||
* @param offset
|
||||
* the offset
|
||||
*/
|
||||
void addCodeOffset( int offset ) {
|
||||
if( sourceMappings != null ) {
|
||||
for( SourceMapping mapping : sourceMappings ) {
|
||||
mapping.addOffset( offset );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user