"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/javascript/private/fragment.bzl" (17 Feb 2023, 3524 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library")
2
3 def _internal_closure_fragment_export_impl(ctx):
4 ctx.actions.write(
5 output = ctx.outputs.out,
6 content = """
7 goog.require('%s');
8 goog.exportSymbol('_', %s);
9 """ % (ctx.attr.module, ctx.attr.function),
10 )
11
12 _internal_closure_fragment_export = rule(
13 implementation = _internal_closure_fragment_export_impl,
14 attrs = {
15 "function": attr.string(mandatory = True),
16 "module": attr.string(mandatory = True),
17 },
18 outputs = {"out": "%{name}.js"},
19 )
20
21 def _closure_fragment_impl(ctx):
22 defs = ctx.attr.defines + [
23 "goog.userAgent.ASSUME_MOBILE_WEBKIT=true",
24 "goog.userAgent.product.ASSUME_ANDROID=true",
25 ]
26
27 def closure_fragment(
28 name,
29 module,
30 function,
31 browsers = None,
32 **kwargs):
33 if browsers == None:
34 browsers = []
35 if type(browsers) != "list":
36 fail("browsers must be None or a list of strings")
37
38 exports_file_name = "_%s_exports" % name
39 _internal_closure_fragment_export(
40 name = exports_file_name,
41 module = module,
42 function = function,
43 )
44
45 exports_lib_name = "%s_lib" % exports_file_name
46 closure_js_library(
47 name = exports_lib_name,
48 srcs = [exports_file_name],
49 deps = kwargs.get("deps", []),
50 )
51
52 # Wrap the output in two functions. The outer function ensures the
53 # compiled fragment never pollutes the global scope by using its
54 # own scope on each invocation. We must import window.navigator into
55 # this unique scope since Closure's goog.userAgent package assumes
56 # navigator and document are defined on goog.global. Normally, this
57 # would be window, but we are explicitly defining the fragment so that
58 # goog.global is _not_ window.
59 # See http://code.google.com/p/selenium/issues/detail?id=1333
60 wrapper = (
61 "function(){" +
62 "return (function(){%output%; return this._.apply(null,arguments);}).apply({" +
63 "navigator:typeof window!='undefined'?window.navigator:null," +
64 "document:typeof window!='undefined'?window.document:null" +
65 "}, arguments);}"
66 )
67
68 browser_defs = {
69 "*": [],
70 "android": [
71 "--define=goog.userAgent.ASSUME_MOBILE_WEBKIT=true",
72 "--define=goog.userAgent.product.ASSUME_ANDROID=true",
73 ],
74 "chrome": [
75 "--define=goog.userAgent.ASSUME_WEBKIT=true",
76 "--define=goog.userAgent.product.ASSUME_CHROME=true",
77 "--define=goog.NATIVE_ARRAY_PROTOTYPES=false",
78 "--use_types_for_optimization=false",
79 ],
80 "ie": [
81 "--define=goog.userAgent.ASSUME_IE=true",
82 ],
83 "ios": [
84 "--define=goog.userAgent.ASSUME_MOBILE_WEBKIT=true",
85 ],
86 "firefox": [
87 "--define=goog.userAgent.ASSUME_GECKO=true",
88 "--define=goog.userAgent.product.ASSUME_FIREFOX=true",
89 ],
90 }
91 for browser, defs in browser_defs.items():
92 if len(browsers) > 0 and (browser == "*" or browser not in browsers):
93 continue
94
95 bin_name = name
96 if browser != "*":
97 bin_name = bin_name + "-" + browser
98
99 closure_js_binary(
100 name = bin_name,
101 deps = [":" + exports_lib_name],
102 defs = kwargs.get("defs", []) + defs,
103 output_wrapper = wrapper,
104 visibility = kwargs.get("visibility"),
105 )