diff --git a/pkg/dart2wasm/lib/constants.dart b/pkg/dart2wasm/lib/constants.dart index a29932ec60f..d4279aa6dfd 100644 --- a/pkg/dart2wasm/lib/constants.dart +++ b/pkg/dart2wasm/lib/constants.dart @@ -175,8 +175,8 @@ class Constants { ..add(oneByteStringsAsBytes)) .toBytes(); - w.Memory stringMemory = - m.addMemory(false, stringsAsBytes.length, stringsAsBytes.length); + double minSize = stringsAsBytes.length / w.Module.memoryBlockSize; + w.Memory stringMemory = m.addMemory(false, minSize.ceil(), minSize.ceil()); m.addDataSegment(stringsAsBytes, stringMemory, 0); makeStringFunctionBody(translator.oneByteStringClass, oneByteStringFunction, (b) { diff --git a/pkg/wasm_builder/lib/src/module.dart b/pkg/wasm_builder/lib/src/module.dart index ced6ed4ca1a..d38f51d01bb 100644 --- a/pkg/wasm_builder/lib/src/module.dart +++ b/pkg/wasm_builder/lib/src/module.dart @@ -35,6 +35,8 @@ class Module with SerializerMixin { int functionNameCount = 0; + static const int memoryBlockSize = 0x10000; + /// Create a new, initially empty, module. /// /// The [watchPoints] is a list of byte offsets within the final module of @@ -170,7 +172,8 @@ class Module with SerializerMixin { initialContent ??= Uint8List(0); assert((memory != null) == (offset != null)); assert(memory == null || - offset! >= 0 && offset + initialContent.length <= memory.minSize); + offset! >= 0 && + offset + initialContent.length <= memory.minSize * memoryBlockSize); final DataSegment data = DataSegment(dataSegments.length, initialContent, memory, offset); dataSegments.add(data);