File tree Expand file tree Collapse file tree 6 files changed +61
-2
lines changed
fixtures/proto-override-dedup@test Expand file tree Collapse file tree 6 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -374,15 +374,23 @@ def check_injection_manager(ext_dir):
374374
375375 # WS1-D: Detect direct prototype overrides
376376 prototype_overrides = []
377+ seen_overrides = set ()
377378 for filepath in js_files :
378379 content = strip_comments (read_file (filepath ))
379380 rel = os .path .relpath (filepath , ext_dir )
380381 # SomeClass.prototype.methodName = ...
381382 for m in re .finditer (r'(\w+\.prototype\.\w+)\s*=' , content ):
382- prototype_overrides .append ((rel , m .group (1 )))
383+ key = (rel , m .group (1 ))
384+ if key not in seen_overrides :
385+ seen_overrides .add (key )
386+ prototype_overrides .append (key )
383387 # Object.assign(SomeClass.prototype, ...)
384388 for m in re .finditer (r'Object\.assign\s*\(\s*(\w+\.prototype)' , content ):
385- prototype_overrides .append ((rel , f"Object.assign({ m .group (1 )} , ...)" ))
389+ label = f"Object.assign({ m .group (1 )} , ...)"
390+ key = (rel , label )
391+ if key not in seen_overrides :
392+ seen_overrides .add (key )
393+ prototype_overrides .append (key )
386394
387395 if prototype_overrides :
388396 # Check if disable() restores prototypes
Original file line number Diff line number Diff line change 1+ # Field test #10: prototype-override deduplication (closes #28)
2+
3+ # --- proto-override-dedup (each prototype warned only once) ---
4+ echo " === proto-override-dedup ==="
5+ run_lint " proto-override-dedup@test"
6+ assert_output_contains " prototype override detected" " \[WARN\].*lifecycle/prototype-override.*BackgroundMenu.prototype.open"
7+ assert_output_contains " search prototype override detected" " \[WARN\].*lifecycle/prototype-override.*SearchController.prototype.startSearch"
8+ echo " "
Original file line number Diff line number Diff line change 1+ SPDX-License-Identifier: GPL-2.0-or-later
Original file line number Diff line number Diff line change 1+ import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js' ;
2+ import { API } from './lib/api.js' ;
3+
4+ export default class TestExtension extends Extension {
5+ enable ( ) {
6+ this . _api = new API ( ) ;
7+ this . _api . open ( ) ;
8+ }
9+
10+ disable ( ) {
11+ this . _api . close ( ) ;
12+ this . _api = null ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ import * as BackgroundMenu from 'resource:///org/gnome/shell/ui/backgroundMenu.js' ;
2+ import * as Search from 'resource:///org/gnome/shell/ui/search.js' ;
3+
4+ export class API {
5+ #originals = { } ;
6+
7+ open ( ) {
8+ // Override prototype — saves original first
9+ this . #originals[ 'bgOpen' ] = BackgroundMenu . BackgroundMenu . prototype . open ;
10+ BackgroundMenu . BackgroundMenu . prototype . open = ( ) => { } ;
11+
12+ this . #originals[ 'startSearch' ] = Search . SearchController . prototype . startSearch ;
13+ Search . SearchController . prototype . startSearch = ( ) => { } ;
14+ }
15+
16+ close ( ) {
17+ // Restore originals
18+ BackgroundMenu . BackgroundMenu . prototype . open = this . #originals[ 'bgOpen' ] ;
19+ Search . SearchController . prototype . startSearch = this . #originals[ 'startSearch' ] ;
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ {
2+ "uuid" : " proto-override-dedup@test" ,
3+ "name" : " Test Proto Override Dedup" ,
4+ "description" : " Tests that prototype override warnings are deduplicated" ,
5+ "shell-version" : [" 48" ],
6+ "url" : " https://example.com"
7+ }
You can’t perform that action at this time.
0 commit comments