From ebc3b88713010626bad2656d0c1754dcb73174c1 Mon Sep 17 00:00:00 2001 From: Tomislav Jovanovic Date: Sat, 16 Mar 2024 05:58:33 +0000 Subject: [PATCH] Bug 1880764 - Don't expose [noscript] members to TypeScript r=mossop,nika This check was in early versions of D197618, but got lost in a refactoring. Apparently xpctest idls don't include [noscript] members, so I added some. Differential Revision: https://phabricator.services.mozilla.com/D204752 --- js/xpconnect/tests/idl/xpctest_utils.idl | 23 +++++++++++++++++++++++ tools/ts/fixtures/xpctest.d.ts | 6 ++++++ xpcom/idl-parser/xpidl/fixtures/xpctest.d.json | 26 ++++++++++++++++++++++++++ xpcom/idl-parser/xpidl/typescript.py | 4 ++-- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/js/xpconnect/tests/idl/xpctest_utils.idl b/js/xpconnect/tests/idl/xpctest_utils.idl index e59814272b7d..db135fcbe1d5 100644 --- a/js/xpconnect/tests/idl/xpctest_utils.idl +++ b/js/xpconnect/tests/idl/xpctest_utils.idl @@ -17,3 +17,26 @@ interface nsIXPCTestFunctionInterface : nsISupports { interface nsIXPCTestUtils : nsISupports { nsIXPCTestFunctionInterface doubleWrapFunction(in nsIXPCTestFunctionInterface f); }; + +/* + * Test that non-[scriptable] interfaces and [noscript] members are not + * generated for TypeScript bindings. + */ + +[uuid(ddf64cfb-668a-4571-a900-0fe2babb6249)] +interface nsIXPCTestNotScriptable : nsISupports { + // Empty. +}; + +[scriptable, uuid(1bbfe703-c67d-4995-b061-564c8a1c39d7)] +interface nsIXPCTestNoScriptMembers : nsISupports { + [noscript] + attribute long noscriptProp; + + attribute long exposedProp; + + [noscript] + void noscriptMethod(in long arg); + + void exposedMethod(in long arg); +}; diff --git a/tools/ts/fixtures/xpctest.d.ts b/tools/ts/fixtures/xpctest.d.ts index c33a2cd40129..6b2863a656bf 100644 --- a/tools/ts/fixtures/xpctest.d.ts +++ b/tools/ts/fixtures/xpctest.d.ts @@ -160,6 +160,11 @@ interface nsIXPCTestUtils extends nsISupports { doubleWrapFunction(f: nsIXPCTestFunctionInterface): nsIXPCTestFunctionInterface; } +interface nsIXPCTestNoScriptMembers extends nsISupports { + exposedProp: i32; + exposedMethod(arg: i32): void; +} + interface nsIXPCComponents_Interfaces { nsIXPCTestObjectReadOnly: nsJSIID; nsIXPCTestObjectReadWrite: nsJSIID; @@ -173,6 +178,7 @@ interface nsIXPCComponents_Interfaces { nsIXPCTestReturnCodeChild: nsJSIID; nsIXPCTestFunctionInterface: nsJSIID; nsIXPCTestUtils: nsJSIID; + nsIXPCTestNoScriptMembers: nsJSIID; } } // global diff --git a/xpcom/idl-parser/xpidl/fixtures/xpctest.d.json b/xpcom/idl-parser/xpidl/fixtures/xpctest.d.json index 8358456d7759..fb3cb7e6b70b 100644 --- a/xpcom/idl-parser/xpidl/fixtures/xpctest.d.json +++ b/xpcom/idl-parser/xpidl/fixtures/xpctest.d.json @@ -1355,6 +1355,32 @@ "type": "nsIXPCTestFunctionInterface" } ] + }, + { + "base": "nsISupports", + "callable": false, + "consts": [], + "enums": [], + "id": "nsIXPCTestNoScriptMembers", + "members": [ + { + "name": "exposedProp", + "readonly": false, + "type": "i32" + }, + { + "args": [ + { + "name": "arg", + "optional": false, + "type": "i32" + } + ], + "iid_is": null, + "name": "exposedMethod", + "type": "void" + } + ] } ], "path": "js/xpconnect/tests/idl/xpctest_utils.idl", diff --git a/xpcom/idl-parser/xpidl/typescript.py b/xpcom/idl-parser/xpidl/typescript.py index daaf9662db27..614a328edf60 100644 --- a/xpcom/idl-parser/xpidl/typescript.py +++ b/xpcom/idl-parser/xpidl/typescript.py @@ -48,9 +48,9 @@ def ts_interface(iface): enums.append(ts_enum(m)) elif isinstance(m, xpidl.ConstMember): consts.append({"name": m.name, "value": m.getValue()}) - elif isinstance(m, xpidl.Attribute): + elif isinstance(m, xpidl.Attribute) and m.isScriptable(): members.append(ts_attribute(m)) - elif isinstance(m, xpidl.Method): + elif isinstance(m, xpidl.Method) and m.isScriptable(): members.append(ts_method(m)) except xpidl.TSNoncompat: # Omit member if any type is unsupported. -- 2.11.4.GIT