Skip to content

Commit

Permalink
[WebIDL] Fixed octet[] evaluation in argument lists (emscripten-core#…
Browse files Browse the repository at this point in the history
  • Loading branch information
agnickolov authored May 15, 2024
1 parent 04535a3 commit 9ac0425
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Taisei Kon <[email protected]>
* YAMAMOTO Takashi <[email protected]>
* Artur Gatin <[email protected]> (copyright owned by Teladoc Health, Inc.)
* Christian Lloyd <[email protected]> (copyright owned by Teladoc Health, Inc.)
2 changes: 1 addition & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7706,7 +7706,7 @@ def test_webidl(self, mode, allow_memory_growth):
# Export things on "TheModule". This matches the typical use pattern of
# the bound library being used as Box2D.* or Ammo.*, and we cannot rely
# on "Module" being always present (closure may remove it).
self.emcc_args += ['--post-js=glue.js', '--extern-post-js=extern-post.js']
self.emcc_args += ['-sEXPORTED_FUNCTIONS=_malloc,_free', '-sEXPORTED_RUNTIME_METHODS=stringToUTF8', '--post-js=glue.js', '--extern-post-js=extern-post.js']
if mode == 'ALL':
self.emcc_args += ['-sASSERTIONS']
if allow_memory_growth:
Expand Down
16 changes: 16 additions & 0 deletions test/webidl/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ TheModule.destroy(factory)

// end of issue 14745

// octet[] to char* (issue 14827)

const arrayTestObj = new TheModule.ArrayArgumentTest();
const bufferAddr = TheModule._malloc(35);
TheModule.stringToUTF8('I should match the member variable', bufferAddr, 35);

const arrayTestResult = arrayTestObj.byteArrayTest(bufferAddr);
const arrayDomStringResult = arrayTestObj.domStringTest('I should match the member variable');
console.log(arrayTestResult);
console.log(arrayDomStringResult);

TheModule.destroy(arrayTestObj)
TheModule._free(bufferAddr);

// end of issue 14827

// Check for overflowing the stack

var before = Date.now();
Expand Down
10 changes: 10 additions & 0 deletions test/webidl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,13 @@ class ObjectFactory {
private:
ObjectProvider m_ObjectProvider;
};

class ArrayArgumentTest {
public:
ArrayArgumentTest() : m_array("I should match the member variable"){};
~ArrayArgumentTest(){};
bool byteArrayTest(const char* arg) { return strcmp(arg, m_array) == 0; }
bool domStringTest(const char* arg) { return strcmp(arg, m_array) == 0; }
private:
const char* m_array;
};
13 changes: 13 additions & 0 deletions test/webidl/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,16 @@ interface ObjectFactory {
void ObjectFactory();
IObjectProvider getProvider();
};

interface ArrayArgumentTest {
void ArrayArgumentTest();
boolean byteArrayTest([Const] byte[] arg);
boolean domStringTest([Const] DOMString arg);
};

[JSImplementation = "ArrayArgumentTest"]
interface JSArrayArgumentTest {
void JSArrayArgumentTest();
boolean byteArrayTest([Const] byte[] arg);
boolean domStringTest([Const] DOMString arg);
};
2 changes: 2 additions & 0 deletions test/webidl/test_ALL.out
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ Parent:42
Aborted(Assertion failed: [CHECK FAILED] Parent::voidStar(something:something): Expecting <pointer>)
Aborted(Assertion failed: [CHECK FAILED] StringUser::Print(anotherString:anotherString): Expecting <string>)
123
true
true
2 changes: 2 additions & 0 deletions test/webidl/test_DEFAULT.out
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ Parent:0
Parent:42
|abc|1|(null)|123|
123
true
true

done.
2 changes: 2 additions & 0 deletions test/webidl/test_FAST.out
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ Parent:0
Parent:42
|abc|1|(null)|123|
123
true
true

done.
4 changes: 1 addition & 3 deletions tools/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ def deref_if_nonpointer(m):


def type_to_cdec(raw):
ret = type_to_c(raw.type.name, non_pointing=True)
if raw.getExtendedAttribute('Const'):
ret = 'const ' + ret
ret = type_to_c(full_typename(raw), non_pointing=True)
if raw.type.name not in interfaces:
return ret
if raw.getExtendedAttribute('Ref'):
Expand Down

0 comments on commit 9ac0425

Please sign in to comment.