Skip to content

Commit b9c357f

Browse files
authored
JavaScript: have File.setContents() take only the contents as a parameter.
2 parents c67083a + 542590f commit b9c357f

23 files changed

+194
-521
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ You might also be interested in our [users](https://groups.google.com/forum/#!fo
1212
Please [contact us](https://opencor.ws/libopencor/contactUs.html) if you have any questions about libOpenCOR.
1313

1414
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/opencor/libopencor)
15+
![Alt](https://repobeats.axiom.co/api/embed/e57859796c7c35c163c88238f9bfd3f2aad9649f.svg "Repobeats analytics image")

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.20260210.0
1+
0.20260211.0

newversion

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
#!/bin/sh
22

3-
# Major version.
3+
# Current version from `VERSION.txt`.
44

5-
major_version=0
5+
version_file=$(cd "$(dirname "$0")" && pwd)/VERSION.txt
66

7-
# Minor version.
7+
old_version=$(cat "$version_file")
8+
9+
old_major_version=$(echo $old_version | cut -d. -f1)
10+
old_minor_version=$(echo $old_version | cut -d. -f2)
11+
old_patch_version=$(echo $old_version | cut -d. -f3)
12+
13+
# Determine the new version based on the current version and the current date.
814

915
now=$(date +%Y%m%d)
10-
minor_version=$now
11-
12-
# Patch version.
13-
14-
patch_version=0
15-
16-
if latest_tag_commit=$(git rev-list --tags --max-count=1 2> /dev/null); then
17-
if git_describe=$(git describe --tags "$latest_tag_commit" 2> /dev/null); then
18-
if echo "$git_describe" | grep -Eo '^v?[0-9]+\.[0-9]+\.[0-9]+' > /dev/null; then
19-
minor=$(echo "$git_describe" | cut -d. -f2)
20-
patch=$(echo "$git_describe" | cut -d. -f3)
21-
patch_version=$patch
22-
23-
if [ "$minor" = "$minor_version" ]; then
24-
patch_version=$((patch_version + 1))
25-
else
26-
patch_version=0
27-
fi
28-
fi
29-
fi
30-
fi
3116

32-
# Full version.
17+
new_major_version=$old_major_version
18+
new_minor_version=$now
3319

34-
version="$major_version.$minor_version.$patch_version"
20+
if [ $old_minor_version -lt $now ]; then
21+
new_patch_version=0
22+
else
23+
new_patch_version=$(($old_patch_version + 1))
24+
fi
25+
26+
new_version="$new_major_version.$new_minor_version.$new_patch_version"
3527

3628
# Update our version file.
3729

38-
echo $version > $(cd $(dirname $0); pwd)/VERSION.txt
30+
echo "$new_version" > "$version_file"
31+
32+
# Display the old and new versions.
33+
34+
printf '\033[1mOld version:\033[0m %s\n' "$old_version"
35+
printf '\033[1mNew version:\033[0m %s\n' "$new_version"

newversion.bat

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,38 @@
22

33
SETLOCAL ENABLEDELAYEDEXPANSION
44

5-
REM Major version.
5+
REM Current version from `VERSION.txt`.
66

7-
SET MajorVersion=0
7+
SET VersionFile=%~dp0VERSION.txt
88

9-
REM Minor version.
9+
FOR /F "usebackq delims=" %%I IN ("%VersionFile%") DO SET OldVersion=%%I
1010

11-
FOR /F "tokens=2 delims==" %%I IN ('wmic os get localdatetime /value') DO SET Now=%%I
12-
SET MinorVersion=!Now:~0,8!
13-
ECHO "MinorVersion: !MinorVersion!"
11+
FOR /F "tokens=1-3 delims=." %%A IN ("!OldVersion!") DO (
12+
SET OldMajorVersion=%%A
13+
SET OldMinorVersion=%%B
14+
SET OldPatchVersion=%%C
15+
)
1416

15-
REM Patch version.
17+
REM Determine the new version based on the current version and the current date.
1618

17-
SET PatchVersion=0
19+
FOR /F "tokens=2 delims==" %%I IN ('wmic os get localdatetime /value') DO SET Now=%%I
1820

19-
FOR /F %%I IN ('git rev-list --tags --max-count=1 2^> NUL') DO (
20-
SET LatestTagCommit=%%I
21-
)
22-
ECHO "LatestTagCommit: !LatestTagCommit!"
23-
24-
IF DEFINED LatestTagCommit (
25-
FOR /F %%I IN ('git describe --tags !LatestTagCommit! 2^> NUL') DO (
26-
SET GitDescribe=%%I
27-
)
28-
ECHO "GitDescribe: !GitDescribe!"
29-
30-
FOR /F "tokens=2,3 delims=." %%A IN ("!GitDescribe!") DO (
31-
SET MinorVersion=%%A
32-
ECHO "MinorVersion: !MinorVersion!"
33-
SET PatchVersion=%%B
34-
ECHO "PatchVersion: !PatchVersion!"
35-
36-
IF "!MinorVersion!"=="!MinorVersion!" (
37-
SET /A PatchVersion+=1
38-
) ELSE (
39-
SET PatchVersion=0
40-
)
41-
)
42-
)
21+
SET NewMajorVersion=!OldMajorVersion!
22+
SET NewMinorVersion=!Now:~0,8!
4323

44-
REM Full version.
24+
IF !OldMinorVersion! LSS !NewMinorVersion! (
25+
SET NewPatchVersion=0
26+
) ELSE (
27+
SET /A NewPatchVersion=!OldPatchVersion! + 1
28+
)
4529

46-
SET Version=!MajorVersion!.!MinorVersion!.!PatchVersion!
30+
SET NewVersion=!NewMajorVersion!.!NewMinorVersion!.!NewPatchVersion!
4731

4832
REM Update our version file.
4933

50-
ECHO !Version! > "%~dp0VERSION.txt"
34+
ECHO !NewVersion! > "%VersionFile%"
35+
36+
REM Display the old and new versions.
37+
38+
ECHO Old version: !OldVersion!
39+
ECHO New version: !NewVersion!

src/bindings/javascript/file.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ void fileApi()
4141

4242
return res;
4343
}))
44-
.function("setContents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis, uintptr_t pContents, size_t pSize) {
45-
auto contents {reinterpret_cast<unsigned char *>(pContents)};
44+
.function("setContents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis, emscripten::val pContents) {
45+
if (pContents.isNull() || pContents.isUndefined()) {
46+
pThis->setContents(libOpenCOR::UnsignedChars {});
4647

47-
pThis->setContents(libOpenCOR::UnsignedChars(contents, contents + pSize));
48+
return;
49+
}
50+
51+
pThis->setContents(emscripten::vecFromJSArray<unsigned char>(pContents));
4852
}))
4953
.property("hasChildFiles", &libOpenCOR::File::hasChildFiles)
5054
.property("childFileCount", &libOpenCOR::File::childFileCount)

tests/bindings/javascript/file.basic.test.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,10 @@ const expectedUnknownFileIssues = [
2929
];
3030

3131
test.describe('File basic tests', () => {
32-
let unknownContentsPtr;
33-
34-
test.before(() => {
35-
unknownContentsPtr = utils.allocateMemory(loc, utils.UNKNOWN_CONTENTS);
36-
});
37-
3832
test.beforeEach(() => {
3933
loc.FileManager.instance().reset();
4034
});
4135

42-
test.after(() => {
43-
utils.freeMemory(loc, unknownContentsPtr);
44-
});
45-
4636
test('Local file', () => {
4737
const file = new loc.File(utils.LOCAL_FILE);
4838

@@ -53,7 +43,7 @@ test.describe('File basic tests', () => {
5343
assert.deepStrictEqual(file.contents(), utils.NO_CONTENTS);
5444
assertIssues(loc, file, expectedNoIssues);
5545

56-
file.setContents(unknownContentsPtr, utils.UNKNOWN_CONTENTS.length);
46+
file.setContents(utils.UNKNOWN_CONTENTS);
5747

5848
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
5949
assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS);
@@ -70,7 +60,7 @@ test.describe('File basic tests', () => {
7060
assert.deepStrictEqual(file.contents(), utils.NO_CONTENTS);
7161
assertIssues(loc, file, expectedNoIssues);
7262

73-
file.setContents(unknownContentsPtr, utils.UNKNOWN_CONTENTS.length);
63+
file.setContents(utils.UNKNOWN_CONTENTS);
7464

7565
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
7666
assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS);
@@ -87,7 +77,7 @@ test.describe('File basic tests', () => {
8777
assert.deepStrictEqual(file.contents(), utils.NO_CONTENTS);
8878
assertIssues(loc, file, expectedNoIssues);
8979

90-
file.setContents(unknownContentsPtr, utils.UNKNOWN_CONTENTS.length);
80+
file.setContents(utils.UNKNOWN_CONTENTS);
9181

9282
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
9383
assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS);

tests/bindings/javascript/file.child.test.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,14 @@ import * as utils from './utils.js';
2323
const loc = await libOpenCOR();
2424

2525
test.describe('File type tests', () => {
26-
let dataset135OmexContentsPtr;
27-
let dataset135JsonContentsPtr;
28-
let dataset157OmexContentsPtr;
29-
let dataset157JsonContentsPtr;
30-
31-
test.before(() => {
32-
dataset135OmexContentsPtr = utils.allocateMemory(loc, utils.DATASET_135_OMEX_CONTENTS);
33-
dataset135JsonContentsPtr = utils.allocateMemory(loc, utils.DATASET_135_JSON_CONTENTS);
34-
dataset157OmexContentsPtr = utils.allocateMemory(loc, utils.DATASET_157_OMEX_CONTENTS);
35-
dataset157JsonContentsPtr = utils.allocateMemory(loc, utils.DATASET_157_JSON_CONTENTS);
36-
});
37-
3826
test.beforeEach(() => {
3927
loc.FileManager.instance().reset();
4028
});
4129

42-
test.after(() => {
43-
utils.freeMemory(loc, dataset135OmexContentsPtr);
44-
utils.freeMemory(loc, dataset135JsonContentsPtr);
45-
utils.freeMemory(loc, dataset157OmexContentsPtr);
46-
utils.freeMemory(loc, dataset157JsonContentsPtr);
47-
});
48-
49-
function doTestDataset(omexContentsPtr, omexContents, jsonContents, specificChildFileNames) {
30+
function doTestDataset(omexContents, jsonContents, specificChildFileNames) {
5031
const file = new loc.File(utils.COMBINE_ARCHIVE);
5132

52-
file.setContents(omexContentsPtr, omexContents.length);
33+
file.setContents(omexContents);
5334

5435
assert.strictEqual(file.hasChildFiles, true);
5536
assert.strictEqual(file.childFileCount, specificChildFileNames.length + 1);
@@ -85,13 +66,13 @@ test.describe('File type tests', () => {
8566
});
8667

8768
test('Dataset 135', () => {
88-
doTestDataset(dataset135OmexContentsPtr, utils.DATASET_135_OMEX_CONTENTS, utils.DATASET_135_JSON_CONTENTS, [
69+
doTestDataset(utils.DATASET_135_OMEX_CONTENTS, utils.DATASET_135_JSON_CONTENTS, [
8970
'HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.cellml'
9071
]);
9172
});
9273

9374
test('Dataset 157', () => {
94-
doTestDataset(dataset157OmexContentsPtr, utils.DATASET_157_OMEX_CONTENTS, utils.DATASET_157_JSON_CONTENTS, [
75+
doTestDataset(utils.DATASET_157_OMEX_CONTENTS, utils.DATASET_157_JSON_CONTENTS, [
9576
'fabbri_et_al_based_composite_SAN_model.cellml',
9677
'fabbri_et_al_based_composite_SAN_model.sedml'
9778
]);

tests/bindings/javascript/file.coverage.test.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,30 @@ import * as utils from './utils.js';
2323
const loc = await libOpenCOR();
2424

2525
test.describe('File coverage tests', () => {
26-
let nullCharacterContentsPtr;
27-
let combineArchiveContentsPtr;
28-
29-
test.before(() => {
30-
nullCharacterContentsPtr = utils.allocateMemory(loc, utils.NULL_CHARACTER_CONTENTS);
31-
combineArchiveContentsPtr = utils.allocateMemory(loc, utils.COMBINE_ARCHIVE_CONTENTS);
32-
});
33-
3426
test.beforeEach(() => {
3527
loc.FileManager.instance().reset();
3628
});
3729

38-
test.after(() => {
39-
utils.freeMemory(loc, nullCharacterContentsPtr);
40-
utils.freeMemory(loc, combineArchiveContentsPtr);
41-
});
42-
4330
test('Empty file', () => {
4431
const file = new loc.File(utils.UNKNOWN_FILE);
4532

46-
file.setContents(null, 0);
33+
file.setContents(null);
4734

4835
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
4936
});
5037

5138
test('File with null character', () => {
5239
const file = new loc.File(utils.UNKNOWN_FILE);
5340

54-
file.setContents(nullCharacterContentsPtr, utils.NULL_CHARACTER_CONTENTS.length);
41+
file.setContents(utils.NULL_CHARACTER_CONTENTS);
5542

5643
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
5744
});
5845

5946
test('SED-ML file with no parent', () => {
6047
const file = new loc.File(utils.SEDML_FILE);
6148

62-
file.setContents(utils.SEDML_CONTENTS, utils.SEDML_CONTENTS.length);
49+
file.setContents(utils.SEDML_CONTENTS);
6350
});
6451

6552
test('Same local file', () => {
@@ -80,7 +67,7 @@ test.describe('File coverage tests', () => {
8067
const file = new loc.File(utils.COMBINE_ARCHIVE);
8168
const fileManager = loc.FileManager.instance();
8269

83-
file.setContents(combineArchiveContentsPtr, utils.COMBINE_ARCHIVE_CONTENTS.length);
70+
file.setContents(utils.COMBINE_ARCHIVE_CONTENTS);
8471

8572
assert.strictEqual(fileManager.fileCount, 3);
8673

tests/bindings/javascript/file.type.test.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,14 @@ import { assertIssues } from './utils.js';
2424
const loc = await libOpenCOR();
2525

2626
test.describe('File type tests', () => {
27-
let unknownContentsPtr;
28-
let cellmlContentsPtr;
29-
let sedmlContentsPtr;
30-
let combineArchiveContentsPtr;
31-
32-
test.before(() => {
33-
unknownContentsPtr = utils.allocateMemory(loc, utils.UNKNOWN_CONTENTS);
34-
cellmlContentsPtr = utils.allocateMemory(loc, utils.CELLML_CONTENTS);
35-
sedmlContentsPtr = utils.allocateMemory(loc, utils.SEDML_CONTENTS);
36-
combineArchiveContentsPtr = utils.allocateMemory(loc, utils.COMBINE_ARCHIVE_CONTENTS);
37-
});
38-
3927
test.beforeEach(() => {
4028
loc.FileManager.instance().reset();
4129
});
4230

43-
test.after(() => {
44-
utils.freeMemory(loc, unknownContentsPtr);
45-
utils.freeMemory(loc, cellmlContentsPtr);
46-
utils.freeMemory(loc, sedmlContentsPtr);
47-
utils.freeMemory(loc, combineArchiveContentsPtr);
48-
});
49-
5031
test('Unknown file', () => {
5132
const file = new loc.File(utils.UNKNOWN_FILE);
5233

53-
file.setContents(unknownContentsPtr, utils.UNKNOWN_CONTENTS.length);
34+
file.setContents(utils.UNKNOWN_CONTENTS);
5435

5536
assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value);
5637
assertIssues(loc, file, [
@@ -61,23 +42,23 @@ test.describe('File type tests', () => {
6142
test('CellML file', () => {
6243
const file = new loc.File(utils.CELLML_FILE);
6344

64-
file.setContents(cellmlContentsPtr, utils.CELLML_CONTENTS.length);
45+
file.setContents(utils.CELLML_CONTENTS);
6546

6647
assert.strictEqual(file.type.value, loc.File.Type.CELLML_FILE.value);
6748
});
6849

6950
test('SED-ML file', () => {
7051
const file = new loc.File(utils.SEDML_FILE);
7152

72-
file.setContents(sedmlContentsPtr, utils.SEDML_CONTENTS.length);
53+
file.setContents(utils.SEDML_CONTENTS);
7354

7455
assert.strictEqual(file.type.value, loc.File.Type.SEDML_FILE.value);
7556
});
7657

7758
test('COMBINE archive', () => {
7859
const file = new loc.File(utils.COMBINE_ARCHIVE);
7960

80-
file.setContents(combineArchiveContentsPtr, utils.COMBINE_ARCHIVE_CONTENTS.length);
61+
file.setContents(utils.COMBINE_ARCHIVE_CONTENTS);
8162

8263
assert.strictEqual(file.type.value, loc.File.Type.COMBINE_ARCHIVE.value);
8364
});

0 commit comments

Comments
 (0)