Skip to content

Commit cc2ffb2

Browse files
authored
WebIDL operators fix (#6879)
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
1 parent f5280d1 commit cc2ffb2

File tree

7 files changed

+12
-2
lines changed

7 files changed

+12
-2
lines changed

tests/webidl/output_ALL.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object
6363
21.12
6464
198
6565
getAsArray: 24
66+
Inner::+= => 2
6667
0
6768
1
6869
34,34

tests/webidl/output_DEFAULT.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object
6363
21.12
6464
198
6565
getAsArray: 24
66+
Inner::+= => 2
6667
0
6768
1
6869
34,34

tests/webidl/output_FAST.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object
6363
21.12
6464
198
6565
getAsArray: 24
66+
Inner::+= => 2
6667
0
6768
1
6869
34,34

tests/webidl/post.js

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ bv2.getAnother().PrintFloat(21.12);
124124
console.log(new TheModule.Inner().get());
125125
console.log('getAsArray: ' + new TheModule.Inner().getAsArray(12));
126126
new TheModule.Inner().mul(2);
127+
new TheModule.Inner().incInPlace(new TheModule.Inner());
127128

128129
console.log(TheModule.enum_value1);
129130
console.log(TheModule.enum_value2);

tests/webidl/test.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ struct VoidPointerUser {
8282

8383
namespace Space {
8484
struct Inner {
85-
Inner() {}
85+
int value;
86+
Inner() : value(1) {}
8687
int get() { return 198; }
8788
Inner& operator*=(float x) { return *this; }
8889
int operator[](int x) { return x*2; }
90+
void operator+=(const Inner& other) {
91+
value += other.value;
92+
printf("Inner::+= => %d\n", value);
93+
}
8994
};
9095
}
9196

tests/webidl/test.idl

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ interface Inner {
7777
long get();
7878
[Operator="*=", Ref] Inner mul(float x);
7979
[Operator="[]"] long getAsArray(long x);
80+
[Operator="+="] void incInPlace([Const, Ref] Inner i);
8081
};
8182

8283
enum AnEnum {

tools/webidl_binder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer, copy,
504504
if class_name != func_scope:
505505
# this function comes from an ancestor class; for operators, we must cast it
506506
cast_self = 'dynamic_cast<' + type_to_c(func_scope) + '>(' + cast_self + ')'
507-
maybe_deref = '*' if sig[0] in interfaces else ''
507+
maybe_deref = deref_if_nonpointer(raw[0])
508508
if '=' in operator:
509509
call = '(*%s %s %s%s)' % (cast_self, operator, maybe_deref, args[0])
510510
elif operator == '[]':

0 commit comments

Comments
 (0)