Skip to content

Commit

Permalink
WebIDL operators fix (#6879)
Browse files Browse the repository at this point in the history
Properly use the right helper function in WebIDL binding of operators. That function handles attributes like Ref etc., without which operator+=(T& other) would not work.

Fixes a bug noticed in kripken/box2d.js#93
  • Loading branch information
kripken authored Jul 23, 2018
1 parent f5280d1 commit cc2ffb2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/webidl/output_ALL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object
21.12
198
getAsArray: 24
Inner::+= => 2
0
1
34,34
Expand Down
1 change: 1 addition & 0 deletions tests/webidl/output_DEFAULT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object
21.12
198
getAsArray: 24
Inner::+= => 2
0
1
34,34
Expand Down
1 change: 1 addition & 0 deletions tests/webidl/output_FAST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object
21.12
198
getAsArray: 24
Inner::+= => 2
0
1
34,34
Expand Down
1 change: 1 addition & 0 deletions tests/webidl/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ bv2.getAnother().PrintFloat(21.12);
console.log(new TheModule.Inner().get());
console.log('getAsArray: ' + new TheModule.Inner().getAsArray(12));
new TheModule.Inner().mul(2);
new TheModule.Inner().incInPlace(new TheModule.Inner());

console.log(TheModule.enum_value1);
console.log(TheModule.enum_value2);
Expand Down
7 changes: 6 additions & 1 deletion tests/webidl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ struct VoidPointerUser {

namespace Space {
struct Inner {
Inner() {}
int value;
Inner() : value(1) {}
int get() { return 198; }
Inner& operator*=(float x) { return *this; }
int operator[](int x) { return x*2; }
void operator+=(const Inner& other) {
value += other.value;
printf("Inner::+= => %d\n", value);
}
};
}

Expand Down
1 change: 1 addition & 0 deletions tests/webidl/test.idl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface Inner {
long get();
[Operator="*=", Ref] Inner mul(float x);
[Operator="[]"] long getAsArray(long x);
[Operator="+="] void incInPlace([Const, Ref] Inner i);
};

enum AnEnum {
Expand Down
2 changes: 1 addition & 1 deletion tools/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer, copy,
if class_name != func_scope:
# this function comes from an ancestor class; for operators, we must cast it
cast_self = 'dynamic_cast<' + type_to_c(func_scope) + '>(' + cast_self + ')'
maybe_deref = '*' if sig[0] in interfaces else ''
maybe_deref = deref_if_nonpointer(raw[0])
if '=' in operator:
call = '(*%s %s %s%s)' % (cast_self, operator, maybe_deref, args[0])
elif operator == '[]':
Expand Down

0 comments on commit cc2ffb2

Please sign in to comment.