johnson 1.2.0 → 2.0.0.pre0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/Manifest.txt +762 -48
- data/README.rdoc +2 -1
- data/Rakefile +90 -18
- data/ext/spidermonkey/conversions.c +9 -2
- data/ext/spidermonkey/ruby_land_proxy.c +1 -1
- data/ext/spidermonkey/runtime.h +1 -1
- data/ext/tracemonkey/context.cc +125 -0
- data/ext/tracemonkey/context.h +19 -0
- data/ext/tracemonkey/conversions.cc +365 -0
- data/ext/tracemonkey/conversions.h +32 -0
- data/ext/tracemonkey/debugger.cc +234 -0
- data/ext/tracemonkey/debugger.h +10 -0
- data/ext/tracemonkey/extconf.rb +37 -0
- data/ext/tracemonkey/extensions.cc +37 -0
- data/ext/tracemonkey/extensions.h +12 -0
- data/ext/tracemonkey/global.cc +40 -0
- data/ext/tracemonkey/global.h +11 -0
- data/ext/tracemonkey/idhash.cc +16 -0
- data/ext/tracemonkey/idhash.h +8 -0
- data/ext/tracemonkey/immutable_node.cc +1199 -0
- data/ext/tracemonkey/immutable_node.cc.erb +559 -0
- data/ext/tracemonkey/immutable_node.h +22 -0
- data/ext/tracemonkey/jroot.h +215 -0
- data/ext/tracemonkey/js_land_proxy.cc +620 -0
- data/ext/tracemonkey/js_land_proxy.h +20 -0
- data/ext/tracemonkey/ruby_land_proxy.cc +618 -0
- data/ext/tracemonkey/ruby_land_proxy.h +38 -0
- data/ext/tracemonkey/runtime.cc +454 -0
- data/ext/tracemonkey/runtime.h +27 -0
- data/ext/tracemonkey/split_global.cc +392 -0
- data/ext/tracemonkey/split_global.h +11 -0
- data/ext/tracemonkey/tracemonkey.cc +23 -0
- data/ext/tracemonkey/tracemonkey.h +32 -0
- data/lib/johnson.rb +12 -4
- data/lib/johnson/error.rb +5 -0
- data/lib/johnson/js/prelude.js +16 -1
- data/lib/johnson/parser.rb +2 -1
- data/lib/johnson/runtime.rb +87 -26
- data/lib/johnson/spidermonkey/runtime.rb +7 -16
- data/lib/johnson/tracemonkey.rb +13 -0
- data/lib/johnson/tracemonkey/context.rb +10 -0
- data/lib/johnson/tracemonkey/debugger.rb +67 -0
- data/lib/johnson/tracemonkey/immutable_node.rb +282 -0
- data/lib/johnson/tracemonkey/js_land_proxy.rb +64 -0
- data/lib/johnson/tracemonkey/mutable_tree_visitor.rb +242 -0
- data/lib/johnson/tracemonkey/ruby_land_proxy.rb +17 -0
- data/lib/johnson/tracemonkey/runtime.rb +80 -0
- data/test/{johnson_test.rb → generic/johnson_test.rb} +1 -1
- data/test/{parser_test.rb → generic/parser_test.rb} +1 -1
- data/test/helper.rb +23 -4
- data/test/johnson/{browser_test.rb → generic/browser_test.rb} +1 -1
- data/test/johnson/{conversions → generic/conversions}/array_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/boolean_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/callable_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/file_test.rb +1 -1
- data/test/johnson/generic/conversions/helper.rb +1 -0
- data/test/johnson/{conversions → generic/conversions}/nil_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/number_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/regexp_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/string_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/struct_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/symbol_test.rb +1 -1
- data/test/johnson/{conversions → generic/conversions}/thread_test.rb +1 -1
- data/test/johnson/{custom_conversions_test.rb → generic/custom_conversions_test.rb} +1 -1
- data/test/johnson/generic/default_test.rb +12 -0
- data/test/johnson/{error_test.rb → generic/error_test.rb} +1 -1
- data/test/johnson/{extensions_test.rb → generic/extensions_test.rb} +1 -1
- data/test/johnson/generic/helper.rb +1 -0
- data/test/johnson/{nodes → generic/nodes}/array_literal_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/array_node_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/binary_node_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/bracket_access_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/delete_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/do_while_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/dot_accessor_test.rb +1 -1
- data/test/johnson/generic/nodes/export_test.rb +11 -0
- data/test/johnson/{nodes → generic/nodes}/for_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/function_test.rb +1 -1
- data/test/johnson/generic/nodes/helper.rb +1 -0
- data/test/johnson/{nodes → generic/nodes}/if_test.rb +16 -6
- data/test/johnson/generic/nodes/import_test.rb +15 -0
- data/test/johnson/{nodes → generic/nodes}/label_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/let_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/object_literal_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/return_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/semi_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/switch_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/ternary_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/throw_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/try_node_test.rb +36 -6
- data/test/johnson/{nodes → generic/nodes}/typeof_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/unary_node_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/void_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/while_test.rb +1 -1
- data/test/johnson/{nodes → generic/nodes}/with_test.rb +1 -1
- data/test/johnson/{prelude_test.rb → generic/prelude_test.rb} +1 -1
- data/test/johnson/{runtime_test.rb → generic/runtime_test.rb} +3 -6
- data/test/johnson/generic/version_test.rb +13 -0
- data/test/johnson/{visitors → generic/visitors}/dot_visitor_test.rb +1 -1
- data/test/johnson/{visitors → generic/visitors}/enumerating_visitor_test.rb +1 -1
- data/test/johnson/generic/visitors/helper.rb +1 -0
- data/test/johnson/spidermonkey/js_land_proxy_test.rb +1 -5
- data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +11 -7
- data/test/johnson/tracemonkey/context_test.rb +21 -0
- data/test/johnson/tracemonkey/immutable_node_test.rb +34 -0
- data/test/johnson/tracemonkey/js_land_proxy_test.rb +273 -0
- data/test/johnson/tracemonkey/ruby_land_proxy_test.rb +274 -0
- data/test/johnson/tracemonkey/runtime_test.rb +41 -0
- data/test/johnson/tracemonkey/split_global_test.rb +32 -0
- data/vendor/spidermonkey/js.pkg +2 -0
- data/vendor/tracemonkey/Makefile.in +668 -0
- data/vendor/tracemonkey/Makefile.ref +483 -0
- data/vendor/tracemonkey/README.html +54 -0
- data/vendor/tracemonkey/SpiderMonkey.rsp +11 -0
- data/vendor/tracemonkey/Y.js +19 -0
- data/vendor/tracemonkey/aclocal.m4 +9 -0
- data/vendor/tracemonkey/bench.sh +5 -0
- data/vendor/tracemonkey/build/autoconf/acoutput-fast.pl +202 -0
- data/vendor/tracemonkey/build/autoconf/altoptions.m4 +154 -0
- data/vendor/tracemonkey/build/autoconf/config.guess +1537 -0
- data/vendor/tracemonkey/build/autoconf/config.sub +1595 -0
- data/vendor/tracemonkey/build/autoconf/install-sh +119 -0
- data/vendor/tracemonkey/build/autoconf/make-makefile +315 -0
- data/vendor/tracemonkey/build/autoconf/match-dir.sh +101 -0
- data/vendor/tracemonkey/build/autoconf/moznbytetype.m4 +136 -0
- data/vendor/tracemonkey/build/autoconf/nspr.m4 +82 -0
- data/vendor/tracemonkey/build/autoconf/pkg.m4 +59 -0
- data/vendor/tracemonkey/build/autoconf/update-makefile.sh +118 -0
- data/vendor/tracemonkey/build/cygwin-wrapper +75 -0
- data/vendor/tracemonkey/build/hcc +111 -0
- data/vendor/tracemonkey/build/hcpp +155 -0
- data/vendor/tracemonkey/build/unix/mddepend.pl +165 -0
- data/vendor/tracemonkey/build/unix/uniq.pl +63 -0
- data/vendor/tracemonkey/build/win32/pgomerge.py +40 -0
- data/vendor/tracemonkey/builtins.tbl +91 -0
- data/vendor/tracemonkey/call.js +13 -0
- data/vendor/tracemonkey/config.mk +206 -0
- data/vendor/tracemonkey/config/Makefile.in +106 -0
- data/vendor/tracemonkey/config/Moz/Milestone.pm +232 -0
- data/vendor/tracemonkey/config/autoconf.mk.in +362 -0
- data/vendor/tracemonkey/config/check-sync-dirs.py +103 -0
- data/vendor/tracemonkey/config/check-sync-exceptions +7 -0
- data/vendor/tracemonkey/config/config.mk +881 -0
- data/vendor/tracemonkey/config/fastcwd.pl +66 -0
- data/vendor/tracemonkey/config/gcc_hidden.h +2 -0
- data/vendor/tracemonkey/config/insure.mk +53 -0
- data/vendor/tracemonkey/config/make-system-wrappers.pl +59 -0
- data/vendor/tracemonkey/config/milestone.pl +112 -0
- data/vendor/tracemonkey/config/milestone.txt +13 -0
- data/vendor/tracemonkey/config/mkdepend/Makefile.in +84 -0
- data/vendor/tracemonkey/config/mkdepend/cppsetup.c +233 -0
- data/vendor/tracemonkey/config/mkdepend/def.h +184 -0
- data/vendor/tracemonkey/config/mkdepend/ifparser.c +551 -0
- data/vendor/tracemonkey/config/mkdepend/ifparser.h +83 -0
- data/vendor/tracemonkey/config/mkdepend/imakemdep.h +733 -0
- data/vendor/tracemonkey/config/mkdepend/include.c +337 -0
- data/vendor/tracemonkey/config/mkdepend/main.c +860 -0
- data/vendor/tracemonkey/config/mkdepend/mkdepend.man +382 -0
- data/vendor/tracemonkey/config/mkdepend/parse.c +686 -0
- data/vendor/tracemonkey/config/mkdepend/pr.c +124 -0
- data/vendor/tracemonkey/config/nfspwd.pl +50 -0
- data/vendor/tracemonkey/config/nsinstall.c +481 -0
- data/vendor/tracemonkey/config/nsinstall.py +155 -0
- data/vendor/tracemonkey/config/pathsub.c +247 -0
- data/vendor/tracemonkey/config/pathsub.h +74 -0
- data/vendor/tracemonkey/config/preprocessor.pl +671 -0
- data/vendor/tracemonkey/config/revdepth-nt.pl +48 -0
- data/vendor/tracemonkey/config/revdepth.pl +51 -0
- data/vendor/tracemonkey/config/rules.mk +2310 -0
- data/vendor/tracemonkey/config/static-checking-config.mk +21 -0
- data/vendor/tracemonkey/config/static-checking.js +92 -0
- data/vendor/tracemonkey/config/string-format.js +61 -0
- data/vendor/tracemonkey/config/system-headers +1035 -0
- data/vendor/tracemonkey/config/version.mk +85 -0
- data/vendor/tracemonkey/config/version_win.pl +442 -0
- data/vendor/tracemonkey/configure +14183 -0
- data/vendor/tracemonkey/configure.in +5363 -0
- data/vendor/tracemonkey/correct.sh +23 -0
- data/vendor/tracemonkey/correct/check-3d-morph.js +55 -0
- data/vendor/tracemonkey/correct/check-3d-raytrace.js +445 -0
- data/vendor/tracemonkey/correct/check-access-binary-trees.js +52 -0
- data/vendor/tracemonkey/correct/check-access-fannkuch.js +66 -0
- data/vendor/tracemonkey/correct/check-access-nbody.js +171 -0
- data/vendor/tracemonkey/correct/check-access-nsieve.js +40 -0
- data/vendor/tracemonkey/correct/check-bitops-3bit-bits-in-byte.js +35 -0
- data/vendor/tracemonkey/correct/check-bitops-bits-in-byte.js +24 -0
- data/vendor/tracemonkey/correct/check-bitops-bitwise-and.js +29 -0
- data/vendor/tracemonkey/correct/check-bitops-nsieve-bits.js +40 -0
- data/vendor/tracemonkey/correct/check-controlflow-recursive.js +27 -0
- data/vendor/tracemonkey/correct/check-date-format-tofte.js +302 -0
- data/vendor/tracemonkey/correct/check-date-format-xparb.js +421 -0
- data/vendor/tracemonkey/correct/check-mont.js +119 -0
- data/vendor/tracemonkey/dtoa.c +3335 -0
- data/vendor/tracemonkey/editline/Makefile.in +55 -0
- data/vendor/tracemonkey/editline/Makefile.ref +143 -0
- data/vendor/tracemonkey/editline/README +83 -0
- data/vendor/tracemonkey/editline/editline.3 +175 -0
- data/vendor/tracemonkey/editline/editline.c +1371 -0
- data/vendor/tracemonkey/editline/editline.h +135 -0
- data/vendor/tracemonkey/editline/sysunix.c +182 -0
- data/vendor/tracemonkey/editline/unix.h +82 -0
- data/vendor/tracemonkey/if.js +13 -0
- data/vendor/tracemonkey/imacro_asm.js.in +396 -0
- data/vendor/tracemonkey/imacros.c.out +1034 -0
- data/vendor/tracemonkey/imacros.jsasm +770 -0
- data/vendor/tracemonkey/javascript-trace.d +73 -0
- data/vendor/tracemonkey/jitstats.tbl +55 -0
- data/vendor/tracemonkey/js-config.h.in +82 -0
- data/vendor/tracemonkey/js-config.in +111 -0
- data/vendor/tracemonkey/js.mdp +0 -0
- data/vendor/tracemonkey/js.msg +312 -0
- data/vendor/tracemonkey/js3240.rc +79 -0
- data/vendor/tracemonkey/jsOS240.def +654 -0
- data/vendor/tracemonkey/jsapi.cpp +6005 -0
- data/vendor/tracemonkey/jsapi.h +2727 -0
- data/vendor/tracemonkey/jsarena.cpp +450 -0
- data/vendor/tracemonkey/jsarena.h +318 -0
- data/vendor/tracemonkey/jsarray.cpp +3664 -0
- data/vendor/tracemonkey/jsarray.h +238 -0
- data/vendor/tracemonkey/jsatom.cpp +1244 -0
- data/vendor/tracemonkey/jsatom.h +493 -0
- data/vendor/tracemonkey/jsbit.h +249 -0
- data/vendor/tracemonkey/jsbool.cpp +184 -0
- data/vendor/tracemonkey/jsbool.h +88 -0
- data/vendor/tracemonkey/jsbuiltins.cpp +415 -0
- data/vendor/tracemonkey/jsbuiltins.h +456 -0
- data/vendor/tracemonkey/jsclist.h +139 -0
- data/vendor/tracemonkey/jscntxt.cpp +1816 -0
- data/vendor/tracemonkey/jscntxt.h +1541 -0
- data/vendor/tracemonkey/jscompat.h +57 -0
- data/vendor/tracemonkey/jsconfig.mk +181 -0
- data/vendor/tracemonkey/jscpucfg.cpp +194 -0
- data/vendor/tracemonkey/jscpucfg.h +91 -0
- data/vendor/tracemonkey/jsdate.cpp +2465 -0
- data/vendor/tracemonkey/jsdate.h +129 -0
- data/vendor/tracemonkey/jsdbgapi.cpp +2017 -0
- data/vendor/tracemonkey/jsdbgapi.h +500 -0
- data/vendor/tracemonkey/jsdhash.cpp +876 -0
- data/vendor/tracemonkey/jsdhash.h +588 -0
- data/vendor/tracemonkey/jsdtoa.cpp +572 -0
- data/vendor/tracemonkey/jsdtoa.h +131 -0
- data/vendor/tracemonkey/jsdtracef.c +318 -0
- data/vendor/tracemonkey/jsdtracef.h +81 -0
- data/vendor/tracemonkey/jsemit.cpp +7292 -0
- data/vendor/tracemonkey/jsemit.h +802 -0
- data/vendor/tracemonkey/jsexn.cpp +1337 -0
- data/vendor/tracemonkey/jsexn.h +96 -0
- data/vendor/tracemonkey/jsfile.cpp +2747 -0
- data/vendor/tracemonkey/jsfile.h +56 -0
- data/vendor/tracemonkey/jsfile.msg +90 -0
- data/vendor/tracemonkey/jsfun.cpp +3089 -0
- data/vendor/tracemonkey/jsfun.h +366 -0
- data/vendor/tracemonkey/jsgc.cpp +3816 -0
- data/vendor/tracemonkey/jsgc.h +429 -0
- data/vendor/tracemonkey/jshash.cpp +477 -0
- data/vendor/tracemonkey/jshash.h +151 -0
- data/vendor/tracemonkey/jsify.pl +483 -0
- data/vendor/tracemonkey/jsinterp.cpp +7441 -0
- data/vendor/tracemonkey/jsinterp.h +666 -0
- data/vendor/tracemonkey/jsinvoke.cpp +42 -0
- data/vendor/tracemonkey/jsiter.cpp +1040 -0
- data/vendor/tracemonkey/jsiter.h +140 -0
- data/vendor/tracemonkey/jskeyword.tbl +124 -0
- data/vendor/tracemonkey/jskwgen.cpp +460 -0
- data/vendor/tracemonkey/jslibmath.h +69 -0
- data/vendor/tracemonkey/jslock.cpp +1512 -0
- data/vendor/tracemonkey/jslock.h +325 -0
- data/vendor/tracemonkey/jslocko.asm +60 -0
- data/vendor/tracemonkey/jslog2.cpp +111 -0
- data/vendor/tracemonkey/jslong.h +167 -0
- data/vendor/tracemonkey/jsmath.cpp +806 -0
- data/vendor/tracemonkey/jsmath.h +63 -0
- data/vendor/tracemonkey/jsnum.cpp +1374 -0
- data/vendor/tracemonkey/jsnum.h +280 -0
- data/vendor/tracemonkey/jsobj.cpp +6165 -0
- data/vendor/tracemonkey/jsobj.h +870 -0
- data/vendor/tracemonkey/json.cpp +1338 -0
- data/vendor/tracemonkey/json.h +108 -0
- data/vendor/tracemonkey/jsopcode.cpp +5484 -0
- data/vendor/tracemonkey/jsopcode.h +434 -0
- data/vendor/tracemonkey/jsopcode.tbl +591 -0
- data/vendor/tracemonkey/jsoplengen.cpp +121 -0
- data/vendor/tracemonkey/jsotypes.h +202 -0
- data/vendor/tracemonkey/jsparse.cpp +9257 -0
- data/vendor/tracemonkey/jsparse.h +900 -0
- data/vendor/tracemonkey/jsprf.cpp +1262 -0
- data/vendor/tracemonkey/jsprf.h +150 -0
- data/vendor/tracemonkey/jsproto.tbl +117 -0
- data/vendor/tracemonkey/jsprvtd.h +366 -0
- data/vendor/tracemonkey/jspubtd.h +585 -0
- data/vendor/tracemonkey/jsregexp.cpp +5051 -0
- data/vendor/tracemonkey/jsregexp.h +199 -0
- data/vendor/tracemonkey/jsreops.tbl +145 -0
- data/vendor/tracemonkey/jsscan.cpp +2040 -0
- data/vendor/tracemonkey/jsscan.h +467 -0
- data/vendor/tracemonkey/jsscope.cpp +1966 -0
- data/vendor/tracemonkey/jsscope.h +487 -0
- data/vendor/tracemonkey/jsscript.cpp +1932 -0
- data/vendor/tracemonkey/jsscript.h +345 -0
- data/vendor/tracemonkey/jsshell.msg +54 -0
- data/vendor/tracemonkey/jsstack.js +167 -0
- data/vendor/tracemonkey/jsstaticcheck.h +69 -0
- data/vendor/tracemonkey/jsstddef.h +87 -0
- data/vendor/tracemonkey/jsstdint.h +96 -0
- data/vendor/tracemonkey/jsstr.cpp +5277 -0
- data/vendor/tracemonkey/jsstr.h +702 -0
- data/vendor/tracemonkey/jstracer.cpp +10991 -0
- data/vendor/tracemonkey/jstracer.h +794 -0
- data/vendor/tracemonkey/jstypes.h +481 -0
- data/vendor/tracemonkey/jsutil.cpp +361 -0
- data/vendor/tracemonkey/jsutil.h +178 -0
- data/vendor/tracemonkey/jsversion.h +243 -0
- data/vendor/tracemonkey/jswince.asm +44 -0
- data/vendor/tracemonkey/jsxdrapi.cpp +800 -0
- data/vendor/tracemonkey/jsxdrapi.h +220 -0
- data/vendor/tracemonkey/jsxml.cpp +8327 -0
- data/vendor/tracemonkey/jsxml.h +305 -0
- data/vendor/tracemonkey/liveconnect/LiveConnect.dsp +157 -0
- data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsp +120 -0
- data/vendor/tracemonkey/liveconnect/LiveConnectShell.dsw +44 -0
- data/vendor/tracemonkey/liveconnect/Makefile.in +105 -0
- data/vendor/tracemonkey/liveconnect/Makefile.ref +169 -0
- data/vendor/tracemonkey/liveconnect/README.html +712 -0
- data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSException.h +14 -0
- data/vendor/tracemonkey/liveconnect/_jni/netscape_javascript_JSObject.h +155 -0
- data/vendor/tracemonkey/liveconnect/classes/Makefile.in +89 -0
- data/vendor/tracemonkey/liveconnect/classes/Makefile.ref +57 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/Makefile.ref +47 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSException.java +140 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSObject.java +183 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSProxy.java +58 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSRunnable.java +70 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/JSUtil.java +59 -0
- data/vendor/tracemonkey/liveconnect/classes/netscape/javascript/Makefile.ref +53 -0
- data/vendor/tracemonkey/liveconnect/config/AIX4.1.mk +45 -0
- data/vendor/tracemonkey/liveconnect/config/AIX4.2.mk +45 -0
- data/vendor/tracemonkey/liveconnect/config/AIX4.3.mk +50 -0
- data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.10.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/HP-UXB.10.20.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/HP-UXB.11.00.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/IRIX6.2.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/IRIX6.3.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/IRIX6.5.mk +43 -0
- data/vendor/tracemonkey/liveconnect/config/Linux_All.mk +73 -0
- data/vendor/tracemonkey/liveconnect/config/OSF1V4.0.mk +65 -0
- data/vendor/tracemonkey/liveconnect/config/OSF1V5.0.mk +62 -0
- data/vendor/tracemonkey/liveconnect/config/SunOS5.5.1.mk +55 -0
- data/vendor/tracemonkey/liveconnect/config/SunOS5.6.mk +39 -0
- data/vendor/tracemonkey/liveconnect/config/SunOS5.7.mk +39 -0
- data/vendor/tracemonkey/liveconnect/config/SunOS5.8.mk +39 -0
- data/vendor/tracemonkey/liveconnect/config/WINNT4.0.mk +53 -0
- data/vendor/tracemonkey/liveconnect/jsj.c +886 -0
- data/vendor/tracemonkey/liveconnect/jsj.msg +98 -0
- data/vendor/tracemonkey/liveconnect/jsj_JSObject.c +1377 -0
- data/vendor/tracemonkey/liveconnect/jsj_JavaArray.c +474 -0
- data/vendor/tracemonkey/liveconnect/jsj_JavaClass.c +737 -0
- data/vendor/tracemonkey/liveconnect/jsj_JavaMember.c +191 -0
- data/vendor/tracemonkey/liveconnect/jsj_JavaObject.c +1079 -0
- data/vendor/tracemonkey/liveconnect/jsj_JavaPackage.c +569 -0
- data/vendor/tracemonkey/liveconnect/jsj_array.c +207 -0
- data/vendor/tracemonkey/liveconnect/jsj_class.c +770 -0
- data/vendor/tracemonkey/liveconnect/jsj_convert.c +902 -0
- data/vendor/tracemonkey/liveconnect/jsj_field.c +421 -0
- data/vendor/tracemonkey/liveconnect/jsj_hash.c +488 -0
- data/vendor/tracemonkey/liveconnect/jsj_hash.h +161 -0
- data/vendor/tracemonkey/liveconnect/jsj_method.c +1825 -0
- data/vendor/tracemonkey/liveconnect/jsj_nodl.c +1 -0
- data/vendor/tracemonkey/liveconnect/jsj_private.h +677 -0
- data/vendor/tracemonkey/liveconnect/jsj_simpleapi.c +219 -0
- data/vendor/tracemonkey/liveconnect/jsj_utils.c +513 -0
- data/vendor/tracemonkey/liveconnect/jsjava.h +316 -0
- data/vendor/tracemonkey/liveconnect/netscape_javascript_JSObject.h +155 -0
- data/vendor/tracemonkey/liveconnect/nsCLiveconnect.cpp +785 -0
- data/vendor/tracemonkey/liveconnect/nsCLiveconnect.h +197 -0
- data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.cpp +118 -0
- data/vendor/tracemonkey/liveconnect/nsCLiveconnectFactory.h +76 -0
- data/vendor/tracemonkey/liveconnect/nsILiveconnect.h +197 -0
- data/vendor/tracemonkey/liveconnect/nsISecureLiveconnect.h +94 -0
- data/vendor/tracemonkey/liveconnect/nsISecurityContext.h +136 -0
- data/vendor/tracemonkey/lock_SunOS.s +119 -0
- data/vendor/tracemonkey/mandelbrot-results.js +3 -0
- data/vendor/tracemonkey/math-partial-sums.js +32 -0
- data/vendor/tracemonkey/math-trace-tests.js +507 -0
- data/vendor/tracemonkey/md5.js +289 -0
- data/vendor/tracemonkey/nanojit/Assembler.cpp +1984 -0
- data/vendor/tracemonkey/nanojit/Assembler.h +375 -0
- data/vendor/tracemonkey/nanojit/Fragmento.cpp +651 -0
- data/vendor/tracemonkey/nanojit/Fragmento.h +237 -0
- data/vendor/tracemonkey/nanojit/LIR.cpp +2314 -0
- data/vendor/tracemonkey/nanojit/LIR.h +879 -0
- data/vendor/tracemonkey/nanojit/LIRopcode.tbl +252 -0
- data/vendor/tracemonkey/nanojit/Native.h +127 -0
- data/vendor/tracemonkey/nanojit/NativeARM.cpp +1742 -0
- data/vendor/tracemonkey/nanojit/NativeARM.h +844 -0
- data/vendor/tracemonkey/nanojit/NativeSparc.cpp +1130 -0
- data/vendor/tracemonkey/nanojit/NativeSparc.h +948 -0
- data/vendor/tracemonkey/nanojit/NativeThumb.cpp +1322 -0
- data/vendor/tracemonkey/nanojit/NativeThumb.h +525 -0
- data/vendor/tracemonkey/nanojit/Nativei386.cpp +1748 -0
- data/vendor/tracemonkey/nanojit/Nativei386.h +857 -0
- data/vendor/tracemonkey/nanojit/RegAlloc.cpp +183 -0
- data/vendor/tracemonkey/nanojit/RegAlloc.h +95 -0
- data/vendor/tracemonkey/nanojit/TraceTreeDrawer.cpp +306 -0
- data/vendor/tracemonkey/nanojit/TraceTreeDrawer.h +88 -0
- data/vendor/tracemonkey/nanojit/avmplus.cpp +56 -0
- data/vendor/tracemonkey/nanojit/avmplus.h +1016 -0
- data/vendor/tracemonkey/nanojit/nanojit.h +253 -0
- data/vendor/tracemonkey/perfect.js +39 -0
- data/vendor/tracemonkey/plify_jsdhash.sed +35 -0
- data/vendor/tracemonkey/prmjtime.cpp +869 -0
- data/vendor/tracemonkey/prmjtime.h +103 -0
- data/vendor/tracemonkey/ref-config/AIX4.1.mk +65 -0
- data/vendor/tracemonkey/ref-config/AIX4.2.mk +64 -0
- data/vendor/tracemonkey/ref-config/AIX4.3.mk +65 -0
- data/vendor/tracemonkey/ref-config/Darwin.mk +85 -0
- data/vendor/tracemonkey/ref-config/Darwin1.3.mk +81 -0
- data/vendor/tracemonkey/ref-config/Darwin1.4.mk +41 -0
- data/vendor/tracemonkey/ref-config/Darwin5.2.mk +81 -0
- data/vendor/tracemonkey/ref-config/Darwin5.3.mk +81 -0
- data/vendor/tracemonkey/ref-config/Darwin64.mk +72 -0
- data/vendor/tracemonkey/ref-config/HP-UXB.10.10.mk +77 -0
- data/vendor/tracemonkey/ref-config/HP-UXB.10.20.mk +77 -0
- data/vendor/tracemonkey/ref-config/HP-UXB.11.00.mk +80 -0
- data/vendor/tracemonkey/ref-config/IRIX.mk +87 -0
- data/vendor/tracemonkey/ref-config/IRIX5.3.mk +44 -0
- data/vendor/tracemonkey/ref-config/IRIX6.1.mk +44 -0
- data/vendor/tracemonkey/ref-config/IRIX6.2.mk +44 -0
- data/vendor/tracemonkey/ref-config/IRIX6.3.mk +44 -0
- data/vendor/tracemonkey/ref-config/IRIX6.5.mk +44 -0
- data/vendor/tracemonkey/ref-config/Linux_All.mk +105 -0
- data/vendor/tracemonkey/ref-config/Mac_OS10.0.mk +82 -0
- data/vendor/tracemonkey/ref-config/OSF1V4.0.mk +72 -0
- data/vendor/tracemonkey/ref-config/OSF1V5.0.mk +69 -0
- data/vendor/tracemonkey/ref-config/SunOS4.1.4.mk +101 -0
- data/vendor/tracemonkey/ref-config/SunOS5.10.mk +50 -0
- data/vendor/tracemonkey/ref-config/SunOS5.3.mk +91 -0
- data/vendor/tracemonkey/ref-config/SunOS5.4.mk +92 -0
- data/vendor/tracemonkey/ref-config/SunOS5.5.1.mk +44 -0
- data/vendor/tracemonkey/ref-config/SunOS5.5.mk +87 -0
- data/vendor/tracemonkey/ref-config/SunOS5.6.mk +89 -0
- data/vendor/tracemonkey/ref-config/SunOS5.7.mk +44 -0
- data/vendor/tracemonkey/ref-config/SunOS5.8.mk +44 -0
- data/vendor/tracemonkey/ref-config/SunOS5.9.mk +44 -0
- data/vendor/tracemonkey/ref-config/WINNT4.0.mk +118 -0
- data/vendor/tracemonkey/ref-config/WINNT5.0.mk +118 -0
- data/vendor/tracemonkey/ref-config/WINNT5.1.mk +118 -0
- data/vendor/tracemonkey/ref-config/WINNT5.2.mk +118 -0
- data/vendor/tracemonkey/ref-config/WINNT6.0.mk +118 -0
- data/vendor/tracemonkey/ref-config/dgux.mk +64 -0
- data/vendor/tracemonkey/resource.h +15 -0
- data/vendor/tracemonkey/rules.mk +206 -0
- data/vendor/tracemonkey/shell/Makefile.in +72 -0
- data/vendor/tracemonkey/shell/js.cpp +4719 -0
- data/vendor/tracemonkey/t/3d-cube.js +337 -0
- data/vendor/tracemonkey/t/3d-morph.js +54 -0
- data/vendor/tracemonkey/t/3d-raytrace.js +441 -0
- data/vendor/tracemonkey/t/access-binary-trees.js +50 -0
- data/vendor/tracemonkey/t/access-fannkuch.js +66 -0
- data/vendor/tracemonkey/t/access-nbody.js +169 -0
- data/vendor/tracemonkey/t/access-nsieve.js +38 -0
- data/vendor/tracemonkey/t/bitops-3bit-bits-in-byte.js +32 -0
- data/vendor/tracemonkey/t/bitops-bits-in-byte.js +21 -0
- data/vendor/tracemonkey/t/bitops-bitwise-and.js +28 -0
- data/vendor/tracemonkey/t/bitops-nsieve-bits.js +32 -0
- data/vendor/tracemonkey/t/controlflow-recursive.js +25 -0
- data/vendor/tracemonkey/t/crypto-aes.js +422 -0
- data/vendor/tracemonkey/t/crypto-md5.js +286 -0
- data/vendor/tracemonkey/t/crypto-sha1.js +224 -0
- data/vendor/tracemonkey/t/date-format-tofte.js +299 -0
- data/vendor/tracemonkey/t/date-format-xparb.js +417 -0
- data/vendor/tracemonkey/t/math-cordic.js +95 -0
- data/vendor/tracemonkey/t/math-partial-sums.js +33 -0
- data/vendor/tracemonkey/t/math-spectral-norm.js +51 -0
- data/vendor/tracemonkey/t/regexp-dna.js +1712 -0
- data/vendor/tracemonkey/t/string-base64.js +135 -0
- data/vendor/tracemonkey/t/string-fasta.js +85 -0
- data/vendor/tracemonkey/t/string-tagcloud.js +265 -0
- data/vendor/tracemonkey/t/string-unpack-code.js +68 -0
- data/vendor/tracemonkey/t/string-validate-input.js +89 -0
- data/vendor/tracemonkey/time.sh +13 -0
- data/vendor/tracemonkey/trace-test.js +5564 -0
- data/vendor/tracemonkey/v8/base.js +187 -0
- data/vendor/tracemonkey/v8/crypto.js +1689 -0
- data/vendor/tracemonkey/v8/deltablue.js +880 -0
- data/vendor/tracemonkey/v8/earley-boyer.js +4682 -0
- data/vendor/tracemonkey/v8/raytrace.js +3418 -0
- data/vendor/tracemonkey/v8/richards.js +539 -0
- data/vendor/tracemonkey/v8/run-crypto.js +44 -0
- data/vendor/tracemonkey/v8/run-deltablue.js +44 -0
- data/vendor/tracemonkey/v8/run-earley-boyer.js +44 -0
- data/vendor/tracemonkey/v8/run-raytrace.js +44 -0
- data/vendor/tracemonkey/v8/run-richards.js +44 -0
- data/vendor/tracemonkey/v8/run.js +49 -0
- data/vendor/tracemonkey/vprof/readme.txt +93 -0
- data/vendor/tracemonkey/vprof/vprof.cpp +360 -0
- data/vendor/tracemonkey/vprof/vprof.h +245 -0
- data/vendor/tracemonkey/xpconnect/Makefile.in +67 -0
- data/vendor/tracemonkey/xpconnect/crashtests/117307-1.html +20 -0
- data/vendor/tracemonkey/xpconnect/crashtests/193710.html +11 -0
- data/vendor/tracemonkey/xpconnect/crashtests/290162-1.html +5 -0
- data/vendor/tracemonkey/xpconnect/crashtests/326615-1.html +16 -0
- data/vendor/tracemonkey/xpconnect/crashtests/328553-1.html +13 -0
- data/vendor/tracemonkey/xpconnect/crashtests/346258-1.html +12 -0
- data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame1.xhtml +16 -0
- data/vendor/tracemonkey/xpconnect/crashtests/346512-1-frame2.xhtml +15 -0
- data/vendor/tracemonkey/xpconnect/crashtests/346512-1.xhtml +30 -0
- data/vendor/tracemonkey/xpconnect/crashtests/382133-1.html +3 -0
- data/vendor/tracemonkey/xpconnect/crashtests/386680-1.html +22 -0
- data/vendor/tracemonkey/xpconnect/crashtests/394810-1.html +4 -0
- data/vendor/tracemonkey/xpconnect/crashtests/400349-1.html +20 -0
- data/vendor/tracemonkey/xpconnect/crashtests/403356-1.html +13 -0
- data/vendor/tracemonkey/xpconnect/crashtests/418139-1.svg +22 -0
- data/vendor/tracemonkey/xpconnect/crashtests/420513-1.html +11 -0
- data/vendor/tracemonkey/xpconnect/crashtests/453935-1.html +37 -0
- data/vendor/tracemonkey/xpconnect/crashtests/462926.html +12 -0
- data/vendor/tracemonkey/xpconnect/crashtests/468552-1.html +18 -0
- data/vendor/tracemonkey/xpconnect/crashtests/471366-1.html +12 -0
- data/vendor/tracemonkey/xpconnect/crashtests/475185-1.html +13 -0
- data/vendor/tracemonkey/xpconnect/crashtests/475291-1.html +14 -0
- data/vendor/tracemonkey/xpconnect/crashtests/503286-1.html +23 -0
- data/vendor/tracemonkey/xpconnect/crashtests/crashtests.list +21 -0
- data/vendor/tracemonkey/xpconnect/idl/Makefile.in +78 -0
- data/vendor/tracemonkey/xpconnect/idl/XPCIDispatch.idl +51 -0
- data/vendor/tracemonkey/xpconnect/idl/mozIJSSubScriptLoader.idl +64 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIActiveXSecurityPolicy.idl +67 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIDispatchSupport.idl +119 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIJSContextStack.idl +85 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIJSRuntimeService.idl +51 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIScriptError.idl +102 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIScriptableInterfaces.idl +67 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptNotify.idl +66 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIXPCScriptable.idl +183 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIXPCSecurityManager.idl +114 -0
- data/vendor/tracemonkey/xpconnect/idl/nsIXPConnect.idl +819 -0
- data/vendor/tracemonkey/xpconnect/idl/xpcIJSModuleLoader.idl +95 -0
- data/vendor/tracemonkey/xpconnect/idl/xpcIJSWeakReference.idl +49 -0
- data/vendor/tracemonkey/xpconnect/idl/xpccomponents.idl +254 -0
- data/vendor/tracemonkey/xpconnect/idl/xpcexception.idl +66 -0
- data/vendor/tracemonkey/xpconnect/idl/xpcjsid.idl +83 -0
- data/vendor/tracemonkey/xpconnect/loader/ISO8601DateUtils.jsm +176 -0
- data/vendor/tracemonkey/xpconnect/loader/Makefile.in +63 -0
- data/vendor/tracemonkey/xpconnect/loader/XPCOMUtils.jsm +267 -0
- data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.cpp +1717 -0
- data/vendor/tracemonkey/xpconnect/loader/mozJSComponentLoader.h +172 -0
- data/vendor/tracemonkey/xpconnect/loader/mozJSLoaderConstructors.h +101 -0
- data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.cpp +360 -0
- data/vendor/tracemonkey/xpconnect/loader/mozJSSubScriptLoader.h +66 -0
- data/vendor/tracemonkey/xpconnect/public/Makefile.in +54 -0
- data/vendor/tracemonkey/xpconnect/public/nsAXPCNativeCallContext.h +89 -0
- data/vendor/tracemonkey/xpconnect/public/nsAutoJSValHolder.h +168 -0
- data/vendor/tracemonkey/xpconnect/public/xpc_map_end.h +327 -0
- data/vendor/tracemonkey/xpconnect/sample/Makefile.in +71 -0
- data/vendor/tracemonkey/xpconnect/sample/README +39 -0
- data/vendor/tracemonkey/xpconnect/sample/xpcsample1.cpp +337 -0
- data/vendor/tracemonkey/xpconnect/sample/xpcsample1.idl +82 -0
- data/vendor/tracemonkey/xpconnect/sample/xpcsample1.js +21 -0
- data/vendor/tracemonkey/xpconnect/shell/Makefile.in +106 -0
- data/vendor/tracemonkey/xpconnect/shell/jsshell.msg +50 -0
- data/vendor/tracemonkey/xpconnect/shell/xpcshell.cpp +1817 -0
- data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.h +43 -0
- data/vendor/tracemonkey/xpconnect/shell/xpcshellMacUtils.mm +54 -0
- data/vendor/tracemonkey/xpconnect/src/Makefile.in +228 -0
- data/vendor/tracemonkey/xpconnect/src/README +3 -0
- data/vendor/tracemonkey/xpconnect/src/XPCCrossOriginWrapper.cpp +1186 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispConvert.cpp +593 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispInlines.h +667 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispInterface.cpp +383 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispObject.cpp +516 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispParamPropJSClass.cpp +223 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispParams.cpp +103 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispPrivate.h +1401 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispTearOff.cpp +547 -0
- data/vendor/tracemonkey/xpconnect/src/XPCDispTypeInfo.cpp +471 -0
- data/vendor/tracemonkey/xpconnect/src/XPCIDispatchClassInfo.cpp +139 -0
- data/vendor/tracemonkey/xpconnect/src/XPCIDispatchExtension.cpp +362 -0
- data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.cpp +1350 -0
- data/vendor/tracemonkey/xpconnect/src/XPCNativeWrapper.h +88 -0
- data/vendor/tracemonkey/xpconnect/src/XPCSafeJSObjectWrapper.cpp +1148 -0
- data/vendor/tracemonkey/xpconnect/src/XPCSystemOnlyWrapper.cpp +718 -0
- data/vendor/tracemonkey/xpconnect/src/XPCWrapper.cpp +850 -0
- data/vendor/tracemonkey/xpconnect/src/XPCWrapper.h +394 -0
- data/vendor/tracemonkey/xpconnect/src/dom_quickstubs.qsconf +568 -0
- data/vendor/tracemonkey/xpconnect/src/nsDispatchSupport.cpp +348 -0
- data/vendor/tracemonkey/xpconnect/src/nsScriptError.cpp +201 -0
- data/vendor/tracemonkey/xpconnect/src/nsXPConnect.cpp +2609 -0
- data/vendor/tracemonkey/xpconnect/src/qsgen.py +1487 -0
- data/vendor/tracemonkey/xpconnect/src/xpc.msg +217 -0
- data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.cpp +148 -0
- data/vendor/tracemonkey/xpconnect/src/xpcJSWeakReference.h +56 -0
- data/vendor/tracemonkey/xpconnect/src/xpccallcontext.cpp +579 -0
- data/vendor/tracemonkey/xpconnect/src/xpccomponents.cpp +4144 -0
- data/vendor/tracemonkey/xpconnect/src/xpccontext.cpp +115 -0
- data/vendor/tracemonkey/xpconnect/src/xpcconvert.cpp +2298 -0
- data/vendor/tracemonkey/xpconnect/src/xpcdebug.cpp +481 -0
- data/vendor/tracemonkey/xpconnect/src/xpcexception.cpp +502 -0
- data/vendor/tracemonkey/xpconnect/src/xpcforwards.h +114 -0
- data/vendor/tracemonkey/xpconnect/src/xpcinlines.h +772 -0
- data/vendor/tracemonkey/xpconnect/src/xpcjsid.cpp +1025 -0
- data/vendor/tracemonkey/xpconnect/src/xpcjsruntime.cpp +1342 -0
- data/vendor/tracemonkey/xpconnect/src/xpclog.cpp +128 -0
- data/vendor/tracemonkey/xpconnect/src/xpclog.h +101 -0
- data/vendor/tracemonkey/xpconnect/src/xpcmaps.cpp +761 -0
- data/vendor/tracemonkey/xpconnect/src/xpcmaps.h +713 -0
- data/vendor/tracemonkey/xpconnect/src/xpcmodule.cpp +136 -0
- data/vendor/tracemonkey/xpconnect/src/xpcprivate.h +4138 -0
- data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.cpp +1128 -0
- data/vendor/tracemonkey/xpconnect/src/xpcquickstubs.h +480 -0
- data/vendor/tracemonkey/xpconnect/src/xpcruntimesvc.cpp +179 -0
- data/vendor/tracemonkey/xpconnect/src/xpcstack.cpp +342 -0
- data/vendor/tracemonkey/xpconnect/src/xpcstring.cpp +139 -0
- data/vendor/tracemonkey/xpconnect/src/xpcthreadcontext.cpp +599 -0
- data/vendor/tracemonkey/xpconnect/src/xpcthrower.cpp +399 -0
- data/vendor/tracemonkey/xpconnect/src/xpcvariant.cpp +850 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappedjs.cpp +670 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappedjsclass.cpp +2015 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappednative.cpp +3482 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeinfo.cpp +945 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappednativejsops.cpp +2003 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappednativeproto.cpp +302 -0
- data/vendor/tracemonkey/xpconnect/src/xpcwrappednativescope.cpp +991 -0
- data/vendor/tracemonkey/xpconnect/tests/Makefile.in +75 -0
- data/vendor/tracemonkey/xpconnect/tests/TestXPC.cpp +785 -0
- data/vendor/tracemonkey/xpconnect/tests/chrome/Makefile.in +51 -0
- data/vendor/tracemonkey/xpconnect/tests/chrome/test_bug500931.xul +43 -0
- data/vendor/tracemonkey/xpconnect/tests/components/Makefile.in +85 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_array.cpp +388 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_attributes.cpp +305 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_calljs.cpp +135 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_child.cpp +225 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_const.cpp +76 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_domstring.cpp +118 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_echo.cpp +616 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_in.cpp +204 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_inout.cpp +171 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_module.cpp +77 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_multiple.cpp +554 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_noisy.cpp +154 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_out.cpp +335 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_overloaded.cpp +250 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_private.h +192 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_string.cpp +185 -0
- data/vendor/tracemonkey/xpconnect/tests/components/xpctest_variant.cpp +355 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.cpp +12 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/StdAfx.h +28 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCDispUtilities.h +28 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.cpp +86 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.def +9 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsp +318 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.dsw +29 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.idl +454 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/XPCIDispatchTest.rc +145 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.cpp +44 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.h +56 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispSimple.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.cpp +221 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.h +53 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestArrays.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.cpp +699 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.h +138 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestMethods.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.cpp +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.h +41 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestNoIDispatch.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.cpp +256 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.h +88 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestProperties.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.cpp +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.h +43 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOff.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.cpp +29 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.h +45 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestScriptOn.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.cpp +177 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.h +50 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/nsXPCDispTestWrappedJS.rgs +23 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/COM/resource.h +36 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Arrays/XPCIDispatchArrayTests.js +54 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Attributes/XPCIDispatchAttributeTests.js +150 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCIDispatchInstantiations.js +122 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/General/XPCStress.js +58 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/Methods/XPCIDispatchMethodTests.js +376 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedCOM/shell.js +377 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/General/XPCIDispatchTestWrappedJS.js +76 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/WrappedJS/shell.js +377 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/exectests.cmd +1 -0
- data/vendor/tracemonkey/xpconnect/tests/idispatch/Tests/jsDriver.pl +1288 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/Makefile.in +61 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest.idl +312 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest2.idl +51 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_attributes.idl +67 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_calljs.idl +59 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_const.idl +61 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_domstring.idl +59 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_in.idl +88 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_inout.idl +86 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_multiple.idl +77 -0
- data/vendor/tracemonkey/xpconnect/tests/idl/xpctest_out.idl +142 -0
- data/vendor/tracemonkey/xpconnect/tests/js/checkid.js +82 -0
- data/vendor/tracemonkey/xpconnect/tests/js/evaluate.js +311 -0
- data/vendor/tracemonkey/xpconnect/tests/js/exceptions-2.js +153 -0
- data/vendor/tracemonkey/xpconnect/tests/js/exceptions-3.js +194 -0
- data/vendor/tracemonkey/xpconnect/tests/js/exceptions-4.js +297 -0
- data/vendor/tracemonkey/xpconnect/tests/js/exceptions-5.js +343 -0
- data/vendor/tracemonkey/xpconnect/tests/js/exceptions.js +230 -0
- data/vendor/tracemonkey/xpconnect/tests/js/javascript.js +96 -0
- data/vendor/tracemonkey/xpconnect/tests/js/multiple-2.js +151 -0
- data/vendor/tracemonkey/xpconnect/tests/js/multiple-3.js +148 -0
- data/vendor/tracemonkey/xpconnect/tests/js/multiple-4.js +152 -0
- data/vendor/tracemonkey/xpconnect/tests/js/multiple.js +137 -0
- data/vendor/tracemonkey/xpconnect/tests/js/notscriptable.js +104 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/simpletest.js +36 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/speed.js +60 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/testxpc.js +464 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/threads.js +74 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/try.js +27 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_array.js +308 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_callcontext.js +68 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_echo.js +636 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_and_sort.js +28 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_constants.js +15 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_enum_create.js +200 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_exceptions.js +167 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_ids.js +135 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_observer.js +36 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_overloaded.js +14 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_primitives.js +141 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_propertybag.js +36 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant.js +339 -0
- data/vendor/tracemonkey/xpconnect/tests/js/old/xpctest_variant_array.js +30 -0
- data/vendor/tracemonkey/xpconnect/tests/js/readonlyattributes.js +74 -0
- data/vendor/tracemonkey/xpconnect/tests/js/readwriteattributes.js +101 -0
- data/vendor/tracemonkey/xpconnect/tests/js/scriptable.js +120 -0
- data/vendor/tracemonkey/xpconnect/tests/js/testin.js +203 -0
- data/vendor/tracemonkey/xpconnect/tests/js/xpcfun.js +234 -0
- data/vendor/tracemonkey/xpconnect/tests/js/xpctest_primitives.js +200 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/Makefile.in +66 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/bug500931_helper.html +7 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/inner.html +7 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug361111.xul +29 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug384632.html +32 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug390488.html +65 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug393269.html +46 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug396851.html +43 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug428021.html +41 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug446584.html +49 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug448587.html +31 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug462428.html +42 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug478438.html +66 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484107.html +100 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug484459.html +36 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_bug500691.html +28 -0
- data/vendor/tracemonkey/xpconnect/tests/mochitest/test_wrappers.html +116 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/bogus_element_type.jsm +1 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/bogus_exports_type.jsm +1 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/bug451678_subscript.js +2 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/component_import.js +144 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importA.jsm +44 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/recursive_importB.jsm +45 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/syntax_error.jsm +1 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_bogus_files.js +88 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_bug408412.js +51 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_bug451678.js +52 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_bug_442086.js +68 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_import.js +127 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_js_weak_references.js +63 -0
- data/vendor/tracemonkey/xpconnect/tests/unit/test_recursive_import.js +62 -0
- data/vendor/tracemonkey/xpconnect/tools/Makefile.in +49 -0
- data/vendor/tracemonkey/xpconnect/tools/idl/Makefile.in +53 -0
- data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsCompiler.idl +60 -0
- data/vendor/tracemonkey/xpconnect/tools/idl/nsIXPCToolsProfiler.idl +57 -0
- data/vendor/tracemonkey/xpconnect/tools/js/CompileJSFiles.js +28 -0
- data/vendor/tracemonkey/xpconnect/tools/js/ListJSFiles.js +18 -0
- data/vendor/tracemonkey/xpconnect/tools/src/Makefile.in +76 -0
- data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsCompiler.cpp +161 -0
- data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsModule.cpp +65 -0
- data/vendor/tracemonkey/xpconnect/tools/src/nsXPCToolsProfiler.cpp +370 -0
- data/vendor/tracemonkey/xpconnect/tools/src/xpctools_private.h +236 -0
- metadata +782 -107
- data/test/johnson/nodes/export_test.rb +0 -9
- data/test/johnson/nodes/import_test.rb +0 -13
- data/test/johnson/version_test.rb +0 -13
@@ -0,0 +1,4144 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2
|
+
* vim: set ts=8 sw=4 et tw=78:
|
3
|
+
*
|
4
|
+
* ***** BEGIN LICENSE BLOCK *****
|
5
|
+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6
|
+
*
|
7
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
8
|
+
* 1.1 (the "License"); you may not use this file except in compliance with
|
9
|
+
* the License. You may obtain a copy of the License at
|
10
|
+
* http://www.mozilla.org/MPL/
|
11
|
+
*
|
12
|
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
13
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
14
|
+
* for the specific language governing rights and limitations under the
|
15
|
+
* License.
|
16
|
+
*
|
17
|
+
* The Original Code is Mozilla Communicator client code, released
|
18
|
+
* March 31, 1998.
|
19
|
+
*
|
20
|
+
* The Initial Developer of the Original Code is
|
21
|
+
* Netscape Communications Corporation.
|
22
|
+
* Portions created by the Initial Developer are Copyright (C) 1998
|
23
|
+
* the Initial Developer. All Rights Reserved.
|
24
|
+
*
|
25
|
+
* Contributor(s):
|
26
|
+
* John Bandhauer <jband@netscape.com> (original author)
|
27
|
+
* Pierre Phaneuf <pp@ludusdesign.com>
|
28
|
+
*
|
29
|
+
* Alternatively, the contents of this file may be used under the terms of
|
30
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
31
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
32
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
33
|
+
* of those above. If you wish to allow use of your version of this file only
|
34
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
35
|
+
* use your version of this file under the terms of the MPL, indicate your
|
36
|
+
* decision by deleting the provisions above and replace them with the notice
|
37
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
38
|
+
* the provisions above, a recipient may use your version of this file under
|
39
|
+
* the terms of any one of the MPL, the GPL or the LGPL.
|
40
|
+
*
|
41
|
+
* ***** END LICENSE BLOCK ***** */
|
42
|
+
|
43
|
+
/* The "Components" xpcom objects for JavaScript. */
|
44
|
+
|
45
|
+
#include "xpcprivate.h"
|
46
|
+
#include "nsReadableUtils.h"
|
47
|
+
#include "xpcIJSModuleLoader.h"
|
48
|
+
#include "nsIScriptObjectPrincipal.h"
|
49
|
+
#include "nsIDOMWindow.h"
|
50
|
+
#include "xpcJSWeakReference.h"
|
51
|
+
#include "XPCWrapper.h"
|
52
|
+
|
53
|
+
#ifdef MOZ_JSLOADER
|
54
|
+
#include "mozJSComponentLoader.h"
|
55
|
+
#endif
|
56
|
+
|
57
|
+
/***************************************************************************/
|
58
|
+
// stuff used by all
|
59
|
+
|
60
|
+
static nsresult ThrowAndFail(uintN errNum, JSContext* cx, JSBool* retval)
|
61
|
+
{
|
62
|
+
XPCThrower::Throw(errNum, cx);
|
63
|
+
*retval = JS_FALSE;
|
64
|
+
return NS_OK;
|
65
|
+
}
|
66
|
+
|
67
|
+
static JSBool
|
68
|
+
JSValIsInterfaceOfType(JSContext *cx, jsval v, REFNSIID iid)
|
69
|
+
{
|
70
|
+
nsCOMPtr<nsIXPConnect> xpc;
|
71
|
+
nsCOMPtr<nsIXPConnectWrappedNative> wn;
|
72
|
+
nsCOMPtr<nsISupports> sup;
|
73
|
+
nsISupports* iface;
|
74
|
+
if(!JSVAL_IS_PRIMITIVE(v) &&
|
75
|
+
nsnull != (xpc = nsXPConnect::GetXPConnect()) &&
|
76
|
+
NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(v),
|
77
|
+
getter_AddRefs(wn))) && wn &&
|
78
|
+
NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface)
|
79
|
+
{
|
80
|
+
NS_RELEASE(iface);
|
81
|
+
return JS_TRUE;
|
82
|
+
}
|
83
|
+
return JS_FALSE;
|
84
|
+
}
|
85
|
+
|
86
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
87
|
+
char* xpc_CloneAllAccess()
|
88
|
+
{
|
89
|
+
static const char allAccess[] = "AllAccess";
|
90
|
+
return (char*)nsMemory::Clone(allAccess, sizeof(allAccess));
|
91
|
+
}
|
92
|
+
|
93
|
+
char * xpc_CheckAccessList(const PRUnichar* wideName, const char* list[])
|
94
|
+
{
|
95
|
+
nsCAutoString asciiName;
|
96
|
+
CopyUTF16toUTF8(nsDependentString(wideName), asciiName);
|
97
|
+
|
98
|
+
for(const char** p = list; *p; p++)
|
99
|
+
if(!strcmp(*p, asciiName.get()))
|
100
|
+
return xpc_CloneAllAccess();
|
101
|
+
|
102
|
+
return nsnull;
|
103
|
+
}
|
104
|
+
#endif
|
105
|
+
|
106
|
+
/***************************************************************************/
|
107
|
+
|
108
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
109
|
+
out nsIIDPtr array); */
|
110
|
+
NS_IMETHODIMP
|
111
|
+
nsXPCComponents_Interfaces::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
112
|
+
{
|
113
|
+
PRUint32 count = 2;
|
114
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
115
|
+
++count;
|
116
|
+
#endif
|
117
|
+
*aCount = count;
|
118
|
+
nsIID **array;
|
119
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
120
|
+
if(!array)
|
121
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
122
|
+
|
123
|
+
PRUint32 index = 0;
|
124
|
+
nsIID* clone;
|
125
|
+
#define PUSH_IID(id) \
|
126
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
127
|
+
sizeof(nsIID))); \
|
128
|
+
if (!clone) \
|
129
|
+
goto oom; \
|
130
|
+
array[index++] = clone;
|
131
|
+
|
132
|
+
PUSH_IID(nsIScriptableInterfaces)
|
133
|
+
PUSH_IID(nsIXPCScriptable)
|
134
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
135
|
+
PUSH_IID(nsISecurityCheckedComponent)
|
136
|
+
#endif
|
137
|
+
#undef PUSH_IID
|
138
|
+
|
139
|
+
return NS_OK;
|
140
|
+
oom:
|
141
|
+
while (index)
|
142
|
+
nsMemory::Free(array[--index]);
|
143
|
+
nsMemory::Free(array);
|
144
|
+
*aArray = nsnull;
|
145
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
146
|
+
}
|
147
|
+
|
148
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
149
|
+
NS_IMETHODIMP
|
150
|
+
nsXPCComponents_Interfaces::GetHelperForLanguage(PRUint32 language,
|
151
|
+
nsISupports **retval)
|
152
|
+
{
|
153
|
+
*retval = nsnull;
|
154
|
+
return NS_OK;
|
155
|
+
}
|
156
|
+
|
157
|
+
/* readonly attribute string contractID; */
|
158
|
+
NS_IMETHODIMP
|
159
|
+
nsXPCComponents_Interfaces::GetContractID(char * *aContractID)
|
160
|
+
{
|
161
|
+
*aContractID = nsnull;
|
162
|
+
return NS_ERROR_NOT_AVAILABLE;
|
163
|
+
}
|
164
|
+
|
165
|
+
/* readonly attribute string classDescription; */
|
166
|
+
NS_IMETHODIMP
|
167
|
+
nsXPCComponents_Interfaces::GetClassDescription(char * *aClassDescription)
|
168
|
+
{
|
169
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
170
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
171
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
172
|
+
}
|
173
|
+
|
174
|
+
/* readonly attribute nsCIDPtr classID; */
|
175
|
+
NS_IMETHODIMP
|
176
|
+
nsXPCComponents_Interfaces::GetClassID(nsCID * *aClassID)
|
177
|
+
{
|
178
|
+
*aClassID = nsnull;
|
179
|
+
return NS_OK;
|
180
|
+
}
|
181
|
+
|
182
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
183
|
+
NS_IMETHODIMP
|
184
|
+
nsXPCComponents_Interfaces::GetImplementationLanguage(
|
185
|
+
PRUint32 *aImplementationLanguage)
|
186
|
+
{
|
187
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
188
|
+
return NS_OK;
|
189
|
+
}
|
190
|
+
|
191
|
+
/* readonly attribute PRUint32 flags; */
|
192
|
+
NS_IMETHODIMP
|
193
|
+
nsXPCComponents_Interfaces::GetFlags(PRUint32 *aFlags)
|
194
|
+
{
|
195
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
196
|
+
return NS_OK;
|
197
|
+
}
|
198
|
+
|
199
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
200
|
+
NS_IMETHODIMP
|
201
|
+
nsXPCComponents_Interfaces::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
202
|
+
{
|
203
|
+
return NS_ERROR_NOT_AVAILABLE;
|
204
|
+
}
|
205
|
+
|
206
|
+
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces() :
|
207
|
+
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
|
208
|
+
{
|
209
|
+
}
|
210
|
+
|
211
|
+
nsXPCComponents_Interfaces::~nsXPCComponents_Interfaces()
|
212
|
+
{
|
213
|
+
// empty
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/* [noscript] attribute nsIInterfaceInfoManager manager; */
|
218
|
+
NS_IMETHODIMP nsXPCComponents_Interfaces::GetManager(nsIInterfaceInfoManager * *aManager)
|
219
|
+
{
|
220
|
+
*aManager = mManager;
|
221
|
+
NS_IF_ADDREF(*aManager);
|
222
|
+
return NS_OK;
|
223
|
+
}
|
224
|
+
NS_IMETHODIMP nsXPCComponents_Interfaces::SetManager(nsIInterfaceInfoManager * aManager)
|
225
|
+
{
|
226
|
+
mManager = aManager;
|
227
|
+
return NS_OK;
|
228
|
+
}
|
229
|
+
|
230
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Interfaces)
|
231
|
+
NS_INTERFACE_MAP_ENTRY(nsIScriptableInterfaces)
|
232
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
233
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
234
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
235
|
+
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
|
236
|
+
#endif
|
237
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptableInterfaces)
|
238
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
239
|
+
|
240
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Interfaces)
|
241
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Interfaces)
|
242
|
+
|
243
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
244
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Interfaces
|
245
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Interfaces"
|
246
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
247
|
+
#define XPC_MAP_WANT_NEWENUMERATE
|
248
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |\
|
249
|
+
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
250
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
251
|
+
|
252
|
+
|
253
|
+
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
254
|
+
NS_IMETHODIMP
|
255
|
+
nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
256
|
+
JSContext * cx, JSObject * obj,
|
257
|
+
PRUint32 enum_op, jsval * statep,
|
258
|
+
jsid * idp, PRBool *_retval)
|
259
|
+
{
|
260
|
+
nsIEnumerator* e;
|
261
|
+
|
262
|
+
switch(enum_op)
|
263
|
+
{
|
264
|
+
case JSENUMERATE_INIT:
|
265
|
+
{
|
266
|
+
if(!mManager ||
|
267
|
+
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
|
268
|
+
NS_FAILED(e->First()))
|
269
|
+
|
270
|
+
{
|
271
|
+
*statep = JSVAL_NULL;
|
272
|
+
return NS_ERROR_UNEXPECTED;
|
273
|
+
}
|
274
|
+
|
275
|
+
*statep = PRIVATE_TO_JSVAL(e);
|
276
|
+
if(idp)
|
277
|
+
*idp = JSVAL_ZERO; // indicate that we don't know the count
|
278
|
+
return NS_OK;
|
279
|
+
}
|
280
|
+
case JSENUMERATE_NEXT:
|
281
|
+
{
|
282
|
+
nsCOMPtr<nsISupports> isup;
|
283
|
+
|
284
|
+
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
285
|
+
|
286
|
+
while(1)
|
287
|
+
{
|
288
|
+
if(NS_ENUMERATOR_FALSE == e->IsDone() &&
|
289
|
+
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup)
|
290
|
+
{
|
291
|
+
e->Next();
|
292
|
+
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
|
293
|
+
if(iface)
|
294
|
+
{
|
295
|
+
JSString* idstr;
|
296
|
+
const char* name;
|
297
|
+
PRBool scriptable;
|
298
|
+
|
299
|
+
if(NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
|
300
|
+
!scriptable)
|
301
|
+
{
|
302
|
+
continue;
|
303
|
+
}
|
304
|
+
|
305
|
+
if(NS_SUCCEEDED(iface->GetNameShared(&name)) && name &&
|
306
|
+
nsnull != (idstr = JS_NewStringCopyZ(cx, name)) &&
|
307
|
+
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
|
308
|
+
{
|
309
|
+
return NS_OK;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
// else...
|
314
|
+
break;
|
315
|
+
}
|
316
|
+
// FALL THROUGH
|
317
|
+
}
|
318
|
+
|
319
|
+
case JSENUMERATE_DESTROY:
|
320
|
+
default:
|
321
|
+
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
322
|
+
NS_IF_RELEASE(e);
|
323
|
+
*statep = JSVAL_NULL;
|
324
|
+
return NS_OK;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
329
|
+
NS_IMETHODIMP
|
330
|
+
nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
331
|
+
JSContext * cx, JSObject * obj,
|
332
|
+
jsval id, PRUint32 flags,
|
333
|
+
JSObject * *objp, PRBool *_retval)
|
334
|
+
{
|
335
|
+
const char* name = nsnull;
|
336
|
+
|
337
|
+
if(mManager &&
|
338
|
+
JSVAL_IS_STRING(id) &&
|
339
|
+
nsnull != (name = JS_GetStringBytes(JSVAL_TO_STRING(id))) &&
|
340
|
+
name[0] != '{') // we only allow interfaces by name here
|
341
|
+
{
|
342
|
+
nsCOMPtr<nsIInterfaceInfo> info;
|
343
|
+
mManager->GetInfoForName(name, getter_AddRefs(info));
|
344
|
+
if(!info)
|
345
|
+
return NS_OK;
|
346
|
+
|
347
|
+
nsCOMPtr<nsIJSIID> nsid =
|
348
|
+
dont_AddRef(static_cast<nsIJSIID*>(nsJSIID::NewID(info)));
|
349
|
+
|
350
|
+
if(nsid)
|
351
|
+
{
|
352
|
+
nsCOMPtr<nsIXPConnect> xpc;
|
353
|
+
wrapper->GetXPConnect(getter_AddRefs(xpc));
|
354
|
+
if(xpc)
|
355
|
+
{
|
356
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
357
|
+
if(NS_SUCCEEDED(xpc->WrapNative(cx, obj,
|
358
|
+
static_cast<nsIJSIID*>(nsid),
|
359
|
+
NS_GET_IID(nsIJSIID),
|
360
|
+
getter_AddRefs(holder))))
|
361
|
+
{
|
362
|
+
JSObject* idobj;
|
363
|
+
if(holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
|
364
|
+
{
|
365
|
+
jsid idid;
|
366
|
+
|
367
|
+
*objp = obj;
|
368
|
+
*_retval = JS_ValueToId(cx, id, &idid) &&
|
369
|
+
JS_DefinePropertyById(cx, obj, idid,
|
370
|
+
OBJECT_TO_JSVAL(idobj),
|
371
|
+
nsnull, nsnull,
|
372
|
+
JSPROP_ENUMERATE |
|
373
|
+
JSPROP_READONLY |
|
374
|
+
JSPROP_PERMANENT);
|
375
|
+
}
|
376
|
+
}
|
377
|
+
}
|
378
|
+
}
|
379
|
+
}
|
380
|
+
return NS_OK;
|
381
|
+
}
|
382
|
+
|
383
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
384
|
+
/* string canCreateWrapper (in nsIIDPtr iid); */
|
385
|
+
NS_IMETHODIMP
|
386
|
+
nsXPCComponents_Interfaces::CanCreateWrapper(const nsIID * iid, char **_retval)
|
387
|
+
{
|
388
|
+
// We let anyone do this...
|
389
|
+
*_retval = xpc_CloneAllAccess();
|
390
|
+
return NS_OK;
|
391
|
+
}
|
392
|
+
|
393
|
+
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
394
|
+
NS_IMETHODIMP
|
395
|
+
nsXPCComponents_Interfaces::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
396
|
+
{
|
397
|
+
// If you have to ask, then the answer is NO
|
398
|
+
*_retval = nsnull;
|
399
|
+
return NS_OK;
|
400
|
+
}
|
401
|
+
|
402
|
+
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
403
|
+
NS_IMETHODIMP
|
404
|
+
nsXPCComponents_Interfaces::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
405
|
+
{
|
406
|
+
// If you have to ask, then the answer is NO
|
407
|
+
*_retval = nsnull;
|
408
|
+
return NS_OK;
|
409
|
+
}
|
410
|
+
|
411
|
+
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
412
|
+
NS_IMETHODIMP
|
413
|
+
nsXPCComponents_Interfaces::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
414
|
+
{
|
415
|
+
// If you have to ask, then the answer is NO
|
416
|
+
*_retval = nsnull;
|
417
|
+
return NS_OK;
|
418
|
+
}
|
419
|
+
#endif
|
420
|
+
|
421
|
+
/***************************************************************************/
|
422
|
+
/***************************************************************************/
|
423
|
+
/***************************************************************************/
|
424
|
+
|
425
|
+
class nsXPCComponents_InterfacesByID :
|
426
|
+
public nsIScriptableInterfacesByID,
|
427
|
+
public nsIXPCScriptable,
|
428
|
+
public nsIClassInfo
|
429
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
430
|
+
, public nsISecurityCheckedComponent
|
431
|
+
#endif
|
432
|
+
{
|
433
|
+
public:
|
434
|
+
// all the interface method declarations...
|
435
|
+
NS_DECL_ISUPPORTS
|
436
|
+
NS_DECL_NSISCRIPTABLEINTERFACESBYID
|
437
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
438
|
+
NS_DECL_NSICLASSINFO
|
439
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
440
|
+
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
441
|
+
#endif
|
442
|
+
|
443
|
+
public:
|
444
|
+
nsXPCComponents_InterfacesByID();
|
445
|
+
virtual ~nsXPCComponents_InterfacesByID();
|
446
|
+
|
447
|
+
private:
|
448
|
+
nsCOMPtr<nsIInterfaceInfoManager> mManager;
|
449
|
+
};
|
450
|
+
|
451
|
+
/***************************************************************************/
|
452
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
453
|
+
out nsIIDPtr array); */
|
454
|
+
NS_IMETHODIMP
|
455
|
+
nsXPCComponents_InterfacesByID::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
456
|
+
{
|
457
|
+
PRUint32 count = 2;
|
458
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
459
|
+
++count;
|
460
|
+
#endif
|
461
|
+
*aCount = count;
|
462
|
+
nsIID **array;
|
463
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
464
|
+
if(!array)
|
465
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
466
|
+
|
467
|
+
PRUint32 index = 0;
|
468
|
+
nsIID* clone;
|
469
|
+
#define PUSH_IID(id) \
|
470
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
471
|
+
sizeof(nsIID))); \
|
472
|
+
if (!clone) \
|
473
|
+
goto oom; \
|
474
|
+
array[index++] = clone;
|
475
|
+
|
476
|
+
PUSH_IID(nsIScriptableInterfacesByID)
|
477
|
+
PUSH_IID(nsIXPCScriptable)
|
478
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
479
|
+
PUSH_IID(nsISecurityCheckedComponent)
|
480
|
+
#endif
|
481
|
+
#undef PUSH_IID
|
482
|
+
|
483
|
+
return NS_OK;
|
484
|
+
oom:
|
485
|
+
while (index)
|
486
|
+
nsMemory::Free(array[--index]);
|
487
|
+
nsMemory::Free(array);
|
488
|
+
*aArray = nsnull;
|
489
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
490
|
+
}
|
491
|
+
|
492
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
493
|
+
NS_IMETHODIMP
|
494
|
+
nsXPCComponents_InterfacesByID::GetHelperForLanguage(PRUint32 language,
|
495
|
+
nsISupports **retval)
|
496
|
+
{
|
497
|
+
*retval = nsnull;
|
498
|
+
return NS_OK;
|
499
|
+
}
|
500
|
+
|
501
|
+
/* readonly attribute string contractID; */
|
502
|
+
NS_IMETHODIMP
|
503
|
+
nsXPCComponents_InterfacesByID::GetContractID(char * *aContractID)
|
504
|
+
{
|
505
|
+
*aContractID = nsnull;
|
506
|
+
return NS_ERROR_NOT_AVAILABLE;
|
507
|
+
}
|
508
|
+
|
509
|
+
/* readonly attribute string classDescription; */
|
510
|
+
NS_IMETHODIMP
|
511
|
+
nsXPCComponents_InterfacesByID::GetClassDescription(char * *aClassDescription)
|
512
|
+
{
|
513
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
514
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
515
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
516
|
+
}
|
517
|
+
|
518
|
+
/* readonly attribute nsCIDPtr classID; */
|
519
|
+
NS_IMETHODIMP
|
520
|
+
nsXPCComponents_InterfacesByID::GetClassID(nsCID * *aClassID)
|
521
|
+
{
|
522
|
+
*aClassID = nsnull;
|
523
|
+
return NS_OK;
|
524
|
+
}
|
525
|
+
|
526
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
527
|
+
NS_IMETHODIMP
|
528
|
+
nsXPCComponents_InterfacesByID::GetImplementationLanguage(
|
529
|
+
PRUint32 *aImplementationLanguage)
|
530
|
+
{
|
531
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
532
|
+
return NS_OK;
|
533
|
+
}
|
534
|
+
|
535
|
+
/* readonly attribute PRUint32 flags; */
|
536
|
+
NS_IMETHODIMP
|
537
|
+
nsXPCComponents_InterfacesByID::GetFlags(PRUint32 *aFlags)
|
538
|
+
{
|
539
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
540
|
+
return NS_OK;
|
541
|
+
}
|
542
|
+
|
543
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
544
|
+
NS_IMETHODIMP
|
545
|
+
nsXPCComponents_InterfacesByID::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
546
|
+
{
|
547
|
+
return NS_ERROR_NOT_AVAILABLE;
|
548
|
+
}
|
549
|
+
|
550
|
+
nsXPCComponents_InterfacesByID::nsXPCComponents_InterfacesByID() :
|
551
|
+
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
|
552
|
+
{
|
553
|
+
}
|
554
|
+
|
555
|
+
nsXPCComponents_InterfacesByID::~nsXPCComponents_InterfacesByID()
|
556
|
+
{
|
557
|
+
// empty
|
558
|
+
}
|
559
|
+
|
560
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_InterfacesByID)
|
561
|
+
NS_INTERFACE_MAP_ENTRY(nsIScriptableInterfacesByID)
|
562
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
563
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
564
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
565
|
+
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
|
566
|
+
#endif
|
567
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptableInterfacesByID)
|
568
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
569
|
+
|
570
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_InterfacesByID)
|
571
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_InterfacesByID)
|
572
|
+
|
573
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
574
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_InterfacesByID
|
575
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_InterfacesByID"
|
576
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
577
|
+
#define XPC_MAP_WANT_NEWENUMERATE
|
578
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |\
|
579
|
+
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
580
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
581
|
+
|
582
|
+
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
583
|
+
NS_IMETHODIMP
|
584
|
+
nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
585
|
+
JSContext * cx, JSObject * obj,
|
586
|
+
PRUint32 enum_op, jsval * statep,
|
587
|
+
jsid * idp, PRBool *_retval)
|
588
|
+
{
|
589
|
+
nsIEnumerator* e;
|
590
|
+
|
591
|
+
switch(enum_op)
|
592
|
+
{
|
593
|
+
case JSENUMERATE_INIT:
|
594
|
+
{
|
595
|
+
if(!mManager ||
|
596
|
+
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
|
597
|
+
NS_FAILED(e->First()))
|
598
|
+
|
599
|
+
{
|
600
|
+
*statep = JSVAL_NULL;
|
601
|
+
return NS_ERROR_UNEXPECTED;
|
602
|
+
}
|
603
|
+
|
604
|
+
*statep = PRIVATE_TO_JSVAL(e);
|
605
|
+
if(idp)
|
606
|
+
*idp = JSVAL_ZERO; // indicate that we don't know the count
|
607
|
+
return NS_OK;
|
608
|
+
}
|
609
|
+
case JSENUMERATE_NEXT:
|
610
|
+
{
|
611
|
+
nsCOMPtr<nsISupports> isup;
|
612
|
+
|
613
|
+
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
614
|
+
|
615
|
+
while(1)
|
616
|
+
{
|
617
|
+
if(NS_ENUMERATOR_FALSE == e->IsDone() &&
|
618
|
+
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup)
|
619
|
+
{
|
620
|
+
e->Next();
|
621
|
+
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
|
622
|
+
if(iface)
|
623
|
+
{
|
624
|
+
nsIID const *iid;
|
625
|
+
char idstr[NSID_LENGTH];
|
626
|
+
JSString* jsstr;
|
627
|
+
PRBool scriptable;
|
628
|
+
|
629
|
+
if(NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
|
630
|
+
!scriptable)
|
631
|
+
{
|
632
|
+
continue;
|
633
|
+
}
|
634
|
+
|
635
|
+
if(NS_SUCCEEDED(iface->GetIIDShared(&iid)))
|
636
|
+
{
|
637
|
+
iid->ToProvidedString(idstr);
|
638
|
+
jsstr = JS_NewStringCopyZ(cx, idstr);
|
639
|
+
if (jsstr &&
|
640
|
+
JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp))
|
641
|
+
{
|
642
|
+
return NS_OK;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
}
|
646
|
+
}
|
647
|
+
// else...
|
648
|
+
break;
|
649
|
+
}
|
650
|
+
// FALL THROUGH
|
651
|
+
}
|
652
|
+
|
653
|
+
case JSENUMERATE_DESTROY:
|
654
|
+
default:
|
655
|
+
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
656
|
+
NS_IF_RELEASE(e);
|
657
|
+
*statep = JSVAL_NULL;
|
658
|
+
return NS_OK;
|
659
|
+
}
|
660
|
+
}
|
661
|
+
|
662
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
663
|
+
NS_IMETHODIMP
|
664
|
+
nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
665
|
+
JSContext * cx, JSObject * obj,
|
666
|
+
jsval id, PRUint32 flags,
|
667
|
+
JSObject * *objp, PRBool *_retval)
|
668
|
+
{
|
669
|
+
const jschar* name = nsnull;
|
670
|
+
|
671
|
+
if(mManager &&
|
672
|
+
JSVAL_IS_STRING(id) &&
|
673
|
+
38 == JS_GetStringLength(JSVAL_TO_STRING(id)) &&
|
674
|
+
nsnull != (name = JS_GetStringChars(JSVAL_TO_STRING(id))))
|
675
|
+
{
|
676
|
+
nsID iid;
|
677
|
+
if (!iid.Parse(NS_ConvertUTF16toUTF8(reinterpret_cast<const PRUnichar*>
|
678
|
+
(name)).get()))
|
679
|
+
return NS_OK;
|
680
|
+
|
681
|
+
nsCOMPtr<nsIInterfaceInfo> info;
|
682
|
+
mManager->GetInfoForIID(&iid, getter_AddRefs(info));
|
683
|
+
if(!info)
|
684
|
+
return NS_OK;
|
685
|
+
|
686
|
+
nsCOMPtr<nsIJSIID> nsid =
|
687
|
+
dont_AddRef(static_cast<nsIJSIID*>(nsJSIID::NewID(info)));
|
688
|
+
|
689
|
+
if (!nsid)
|
690
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
691
|
+
|
692
|
+
nsCOMPtr<nsIXPConnect> xpc;
|
693
|
+
wrapper->GetXPConnect(getter_AddRefs(xpc));
|
694
|
+
if(xpc)
|
695
|
+
{
|
696
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
697
|
+
if(NS_SUCCEEDED(xpc->WrapNative(cx, obj,
|
698
|
+
static_cast<nsIJSIID*>(nsid),
|
699
|
+
NS_GET_IID(nsIJSIID),
|
700
|
+
getter_AddRefs(holder))))
|
701
|
+
{
|
702
|
+
JSObject* idobj;
|
703
|
+
if(holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
|
704
|
+
{
|
705
|
+
jsid idid;
|
706
|
+
|
707
|
+
*objp = obj;
|
708
|
+
*_retval = JS_ValueToId(cx, id, &idid) &&
|
709
|
+
JS_DefinePropertyById(cx, obj, idid,
|
710
|
+
OBJECT_TO_JSVAL(idobj),
|
711
|
+
nsnull, nsnull,
|
712
|
+
JSPROP_ENUMERATE |
|
713
|
+
JSPROP_READONLY |
|
714
|
+
JSPROP_PERMANENT);
|
715
|
+
}
|
716
|
+
}
|
717
|
+
}
|
718
|
+
}
|
719
|
+
return NS_OK;
|
720
|
+
}
|
721
|
+
|
722
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
723
|
+
/* string canCreateWrapper (in nsIIDPtr iid); */
|
724
|
+
NS_IMETHODIMP
|
725
|
+
nsXPCComponents_InterfacesByID::CanCreateWrapper(const nsIID * iid, char **_retval)
|
726
|
+
{
|
727
|
+
// We let anyone do this...
|
728
|
+
*_retval = xpc_CloneAllAccess();
|
729
|
+
return NS_OK;
|
730
|
+
}
|
731
|
+
|
732
|
+
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
733
|
+
NS_IMETHODIMP
|
734
|
+
nsXPCComponents_InterfacesByID::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
735
|
+
{
|
736
|
+
// If you have to ask, then the answer is NO
|
737
|
+
*_retval = nsnull;
|
738
|
+
return NS_OK;
|
739
|
+
}
|
740
|
+
|
741
|
+
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
742
|
+
NS_IMETHODIMP
|
743
|
+
nsXPCComponents_InterfacesByID::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
744
|
+
{
|
745
|
+
// If you have to ask, then the answer is NO
|
746
|
+
*_retval = nsnull;
|
747
|
+
return NS_OK;
|
748
|
+
}
|
749
|
+
|
750
|
+
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
751
|
+
NS_IMETHODIMP
|
752
|
+
nsXPCComponents_InterfacesByID::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
753
|
+
{
|
754
|
+
// If you have to ask, then the answer is NO
|
755
|
+
*_retval = nsnull;
|
756
|
+
return NS_OK;
|
757
|
+
}
|
758
|
+
#endif
|
759
|
+
|
760
|
+
/***************************************************************************/
|
761
|
+
/***************************************************************************/
|
762
|
+
/***************************************************************************/
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
class nsXPCComponents_Classes :
|
767
|
+
public nsIXPCComponents_Classes,
|
768
|
+
public nsIXPCScriptable,
|
769
|
+
public nsIClassInfo
|
770
|
+
{
|
771
|
+
public:
|
772
|
+
// all the interface method declarations...
|
773
|
+
NS_DECL_ISUPPORTS
|
774
|
+
NS_DECL_NSIXPCCOMPONENTS_CLASSES
|
775
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
776
|
+
NS_DECL_NSICLASSINFO
|
777
|
+
|
778
|
+
public:
|
779
|
+
nsXPCComponents_Classes();
|
780
|
+
virtual ~nsXPCComponents_Classes();
|
781
|
+
};
|
782
|
+
|
783
|
+
/***************************************************************************/
|
784
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
785
|
+
out nsIIDPtr array); */
|
786
|
+
NS_IMETHODIMP
|
787
|
+
nsXPCComponents_Classes::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
788
|
+
{
|
789
|
+
PRUint32 count = 2;
|
790
|
+
*aCount = count;
|
791
|
+
nsIID **array;
|
792
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
793
|
+
if(!array)
|
794
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
795
|
+
|
796
|
+
PRUint32 index = 0;
|
797
|
+
nsIID* clone;
|
798
|
+
#define PUSH_IID(id) \
|
799
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
800
|
+
sizeof(nsIID))); \
|
801
|
+
if (!clone) \
|
802
|
+
goto oom; \
|
803
|
+
array[index++] = clone;
|
804
|
+
|
805
|
+
PUSH_IID(nsIXPCComponents_Classes)
|
806
|
+
PUSH_IID(nsIXPCScriptable)
|
807
|
+
#undef PUSH_IID
|
808
|
+
|
809
|
+
return NS_OK;
|
810
|
+
oom:
|
811
|
+
while (index)
|
812
|
+
nsMemory::Free(array[--index]);
|
813
|
+
nsMemory::Free(array);
|
814
|
+
*aArray = nsnull;
|
815
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
816
|
+
}
|
817
|
+
|
818
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
819
|
+
NS_IMETHODIMP
|
820
|
+
nsXPCComponents_Classes::GetHelperForLanguage(PRUint32 language,
|
821
|
+
nsISupports **retval)
|
822
|
+
{
|
823
|
+
*retval = nsnull;
|
824
|
+
return NS_OK;
|
825
|
+
}
|
826
|
+
|
827
|
+
/* readonly attribute string contractID; */
|
828
|
+
NS_IMETHODIMP
|
829
|
+
nsXPCComponents_Classes::GetContractID(char * *aContractID)
|
830
|
+
{
|
831
|
+
*aContractID = nsnull;
|
832
|
+
return NS_ERROR_NOT_AVAILABLE;
|
833
|
+
}
|
834
|
+
|
835
|
+
/* readonly attribute string classDescription; */
|
836
|
+
NS_IMETHODIMP
|
837
|
+
nsXPCComponents_Classes::GetClassDescription(char * *aClassDescription)
|
838
|
+
{
|
839
|
+
static const char classDescription[] = "XPCComponents_Classes";
|
840
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
841
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
842
|
+
}
|
843
|
+
|
844
|
+
/* readonly attribute nsCIDPtr classID; */
|
845
|
+
NS_IMETHODIMP
|
846
|
+
nsXPCComponents_Classes::GetClassID(nsCID * *aClassID)
|
847
|
+
{
|
848
|
+
*aClassID = nsnull;
|
849
|
+
return NS_OK;
|
850
|
+
}
|
851
|
+
|
852
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
853
|
+
NS_IMETHODIMP
|
854
|
+
nsXPCComponents_Classes::GetImplementationLanguage(
|
855
|
+
PRUint32 *aImplementationLanguage)
|
856
|
+
{
|
857
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
858
|
+
return NS_OK;
|
859
|
+
}
|
860
|
+
|
861
|
+
/* readonly attribute PRUint32 flags; */
|
862
|
+
NS_IMETHODIMP
|
863
|
+
nsXPCComponents_Classes::GetFlags(PRUint32 *aFlags)
|
864
|
+
{
|
865
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
866
|
+
return NS_OK;
|
867
|
+
}
|
868
|
+
|
869
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
870
|
+
NS_IMETHODIMP
|
871
|
+
nsXPCComponents_Classes::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
872
|
+
{
|
873
|
+
return NS_ERROR_NOT_AVAILABLE;
|
874
|
+
}
|
875
|
+
|
876
|
+
nsXPCComponents_Classes::nsXPCComponents_Classes()
|
877
|
+
{
|
878
|
+
}
|
879
|
+
|
880
|
+
nsXPCComponents_Classes::~nsXPCComponents_Classes()
|
881
|
+
{
|
882
|
+
// empty
|
883
|
+
}
|
884
|
+
|
885
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Classes)
|
886
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Classes)
|
887
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
888
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
889
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Classes)
|
890
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
891
|
+
|
892
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Classes)
|
893
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Classes)
|
894
|
+
|
895
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
896
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Classes
|
897
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Classes"
|
898
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
899
|
+
#define XPC_MAP_WANT_NEWENUMERATE
|
900
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |\
|
901
|
+
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
902
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
903
|
+
|
904
|
+
|
905
|
+
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
906
|
+
NS_IMETHODIMP
|
907
|
+
nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
908
|
+
JSContext * cx, JSObject * obj,
|
909
|
+
PRUint32 enum_op, jsval * statep,
|
910
|
+
jsid * idp, PRBool *_retval)
|
911
|
+
{
|
912
|
+
nsISimpleEnumerator* e;
|
913
|
+
|
914
|
+
switch(enum_op)
|
915
|
+
{
|
916
|
+
case JSENUMERATE_INIT:
|
917
|
+
{
|
918
|
+
nsCOMPtr<nsIComponentRegistrar> compMgr;
|
919
|
+
if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr ||
|
920
|
+
NS_FAILED(compMgr->EnumerateContractIDs(&e)) || !e )
|
921
|
+
{
|
922
|
+
*statep = JSVAL_NULL;
|
923
|
+
return NS_ERROR_UNEXPECTED;
|
924
|
+
}
|
925
|
+
|
926
|
+
*statep = PRIVATE_TO_JSVAL(e);
|
927
|
+
if(idp)
|
928
|
+
*idp = JSVAL_ZERO; // indicate that we don't know the count
|
929
|
+
return NS_OK;
|
930
|
+
}
|
931
|
+
case JSENUMERATE_NEXT:
|
932
|
+
{
|
933
|
+
nsCOMPtr<nsISupports> isup;
|
934
|
+
PRBool hasMore;
|
935
|
+
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
936
|
+
|
937
|
+
if(NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore &&
|
938
|
+
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup)
|
939
|
+
{
|
940
|
+
nsCOMPtr<nsISupportsCString> holder(do_QueryInterface(isup));
|
941
|
+
if(holder)
|
942
|
+
{
|
943
|
+
nsCAutoString name;
|
944
|
+
if(NS_SUCCEEDED(holder->GetData(name)))
|
945
|
+
{
|
946
|
+
JSString* idstr = JS_NewStringCopyN(cx, name.get(), name.Length());
|
947
|
+
if(idstr &&
|
948
|
+
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
|
949
|
+
{
|
950
|
+
return NS_OK;
|
951
|
+
}
|
952
|
+
}
|
953
|
+
}
|
954
|
+
}
|
955
|
+
// else... FALL THROUGH
|
956
|
+
}
|
957
|
+
|
958
|
+
case JSENUMERATE_DESTROY:
|
959
|
+
default:
|
960
|
+
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
961
|
+
NS_IF_RELEASE(e);
|
962
|
+
*statep = JSVAL_NULL;
|
963
|
+
return NS_OK;
|
964
|
+
}
|
965
|
+
}
|
966
|
+
|
967
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
968
|
+
NS_IMETHODIMP
|
969
|
+
nsXPCComponents_Classes::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
970
|
+
JSContext * cx, JSObject * obj,
|
971
|
+
jsval id, PRUint32 flags,
|
972
|
+
JSObject * *objp, PRBool *_retval)
|
973
|
+
|
974
|
+
{
|
975
|
+
const char* name = nsnull;
|
976
|
+
|
977
|
+
if(JSVAL_IS_STRING(id) &&
|
978
|
+
nsnull != (name = JS_GetStringBytes(JSVAL_TO_STRING(id))) &&
|
979
|
+
name[0] != '{') // we only allow contractids here
|
980
|
+
{
|
981
|
+
nsCOMPtr<nsIJSCID> nsid =
|
982
|
+
dont_AddRef(static_cast<nsIJSCID*>(nsJSCID::NewID(name)));
|
983
|
+
if(nsid)
|
984
|
+
{
|
985
|
+
nsCOMPtr<nsIXPConnect> xpc;
|
986
|
+
wrapper->GetXPConnect(getter_AddRefs(xpc));
|
987
|
+
if(xpc)
|
988
|
+
{
|
989
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
990
|
+
if(NS_SUCCEEDED(xpc->WrapNative(cx, obj,
|
991
|
+
static_cast<nsIJSCID*>(nsid),
|
992
|
+
NS_GET_IID(nsIJSCID),
|
993
|
+
getter_AddRefs(holder))))
|
994
|
+
{
|
995
|
+
JSObject* idobj;
|
996
|
+
if(holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
|
997
|
+
{
|
998
|
+
jsid idid;
|
999
|
+
|
1000
|
+
*objp = obj;
|
1001
|
+
*_retval = JS_ValueToId(cx, id, &idid) &&
|
1002
|
+
JS_DefinePropertyById(cx, obj, idid,
|
1003
|
+
OBJECT_TO_JSVAL(idobj),
|
1004
|
+
nsnull, nsnull,
|
1005
|
+
JSPROP_ENUMERATE |
|
1006
|
+
JSPROP_READONLY |
|
1007
|
+
JSPROP_PERMANENT);
|
1008
|
+
}
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
return NS_OK;
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
/***************************************************************************/
|
1017
|
+
/***************************************************************************/
|
1018
|
+
/***************************************************************************/
|
1019
|
+
|
1020
|
+
class nsXPCComponents_ClassesByID :
|
1021
|
+
public nsIXPCComponents_ClassesByID,
|
1022
|
+
public nsIXPCScriptable,
|
1023
|
+
public nsIClassInfo
|
1024
|
+
{
|
1025
|
+
public:
|
1026
|
+
// all the interface method declarations...
|
1027
|
+
NS_DECL_ISUPPORTS
|
1028
|
+
NS_DECL_NSIXPCCOMPONENTS_CLASSESBYID
|
1029
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
1030
|
+
NS_DECL_NSICLASSINFO
|
1031
|
+
|
1032
|
+
public:
|
1033
|
+
nsXPCComponents_ClassesByID();
|
1034
|
+
virtual ~nsXPCComponents_ClassesByID();
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
/***************************************************************************/
|
1038
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
1039
|
+
out nsIIDPtr array); */
|
1040
|
+
NS_IMETHODIMP
|
1041
|
+
nsXPCComponents_ClassesByID::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
1042
|
+
{
|
1043
|
+
PRUint32 count = 2;
|
1044
|
+
*aCount = count;
|
1045
|
+
nsIID **array;
|
1046
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
1047
|
+
if(!array)
|
1048
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1049
|
+
|
1050
|
+
PRUint32 index = 0;
|
1051
|
+
nsIID* clone;
|
1052
|
+
#define PUSH_IID(id) \
|
1053
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
1054
|
+
sizeof(nsIID))); \
|
1055
|
+
if (!clone) \
|
1056
|
+
goto oom; \
|
1057
|
+
array[index++] = clone;
|
1058
|
+
|
1059
|
+
PUSH_IID(nsIXPCComponents_ClassesByID)
|
1060
|
+
PUSH_IID(nsIXPCScriptable)
|
1061
|
+
#undef PUSH_IID
|
1062
|
+
|
1063
|
+
return NS_OK;
|
1064
|
+
oom:
|
1065
|
+
while (index)
|
1066
|
+
nsMemory::Free(array[--index]);
|
1067
|
+
nsMemory::Free(array);
|
1068
|
+
*aArray = nsnull;
|
1069
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
1073
|
+
NS_IMETHODIMP
|
1074
|
+
nsXPCComponents_ClassesByID::GetHelperForLanguage(PRUint32 language,
|
1075
|
+
nsISupports **retval)
|
1076
|
+
{
|
1077
|
+
*retval = nsnull;
|
1078
|
+
return NS_OK;
|
1079
|
+
}
|
1080
|
+
|
1081
|
+
/* readonly attribute string contractID; */
|
1082
|
+
NS_IMETHODIMP
|
1083
|
+
nsXPCComponents_ClassesByID::GetContractID(char * *aContractID)
|
1084
|
+
{
|
1085
|
+
*aContractID = nsnull;
|
1086
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
/* readonly attribute string classDescription; */
|
1090
|
+
NS_IMETHODIMP
|
1091
|
+
nsXPCComponents_ClassesByID::GetClassDescription(char * *aClassDescription)
|
1092
|
+
{
|
1093
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
1094
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
1095
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
/* readonly attribute nsCIDPtr classID; */
|
1099
|
+
NS_IMETHODIMP
|
1100
|
+
nsXPCComponents_ClassesByID::GetClassID(nsCID * *aClassID)
|
1101
|
+
{
|
1102
|
+
*aClassID = nsnull;
|
1103
|
+
return NS_OK;
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
1107
|
+
NS_IMETHODIMP
|
1108
|
+
nsXPCComponents_ClassesByID::GetImplementationLanguage(
|
1109
|
+
PRUint32 *aImplementationLanguage)
|
1110
|
+
{
|
1111
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
1112
|
+
return NS_OK;
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
/* readonly attribute PRUint32 flags; */
|
1116
|
+
NS_IMETHODIMP
|
1117
|
+
nsXPCComponents_ClassesByID::GetFlags(PRUint32 *aFlags)
|
1118
|
+
{
|
1119
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
1120
|
+
return NS_OK;
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
1124
|
+
NS_IMETHODIMP
|
1125
|
+
nsXPCComponents_ClassesByID::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
1126
|
+
{
|
1127
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
nsXPCComponents_ClassesByID::nsXPCComponents_ClassesByID()
|
1131
|
+
{
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
nsXPCComponents_ClassesByID::~nsXPCComponents_ClassesByID()
|
1135
|
+
{
|
1136
|
+
// empty
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_ClassesByID)
|
1140
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_ClassesByID)
|
1141
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
1142
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
1143
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_ClassesByID)
|
1144
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
1145
|
+
|
1146
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_ClassesByID)
|
1147
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_ClassesByID)
|
1148
|
+
|
1149
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
1150
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_ClassesByID
|
1151
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_ClassesByID"
|
1152
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
1153
|
+
#define XPC_MAP_WANT_NEWENUMERATE
|
1154
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |\
|
1155
|
+
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
1156
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
1157
|
+
|
1158
|
+
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
1159
|
+
NS_IMETHODIMP
|
1160
|
+
nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
1161
|
+
JSContext * cx, JSObject * obj,
|
1162
|
+
PRUint32 enum_op, jsval * statep,
|
1163
|
+
jsid * idp, PRBool *_retval)
|
1164
|
+
{
|
1165
|
+
nsISimpleEnumerator* e;
|
1166
|
+
|
1167
|
+
switch(enum_op)
|
1168
|
+
{
|
1169
|
+
case JSENUMERATE_INIT:
|
1170
|
+
{
|
1171
|
+
nsCOMPtr<nsIComponentRegistrar> compMgr;
|
1172
|
+
if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr ||
|
1173
|
+
NS_FAILED(compMgr->EnumerateCIDs(&e)) || !e )
|
1174
|
+
{
|
1175
|
+
*statep = JSVAL_NULL;
|
1176
|
+
return NS_ERROR_UNEXPECTED;
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
*statep = PRIVATE_TO_JSVAL(e);
|
1180
|
+
if(idp)
|
1181
|
+
*idp = JSVAL_ZERO; // indicate that we don't know the count
|
1182
|
+
return NS_OK;
|
1183
|
+
}
|
1184
|
+
case JSENUMERATE_NEXT:
|
1185
|
+
{
|
1186
|
+
nsCOMPtr<nsISupports> isup;
|
1187
|
+
PRBool hasMore;
|
1188
|
+
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
1189
|
+
|
1190
|
+
if(NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore &&
|
1191
|
+
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup)
|
1192
|
+
{
|
1193
|
+
nsCOMPtr<nsISupportsID> holder(do_QueryInterface(isup));
|
1194
|
+
if(holder)
|
1195
|
+
{
|
1196
|
+
char* name;
|
1197
|
+
if(NS_SUCCEEDED(holder->ToString(&name)) && name)
|
1198
|
+
{
|
1199
|
+
JSString* idstr = JS_NewStringCopyZ(cx, name);
|
1200
|
+
nsMemory::Free(name);
|
1201
|
+
if(idstr &&
|
1202
|
+
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
|
1203
|
+
{
|
1204
|
+
return NS_OK;
|
1205
|
+
}
|
1206
|
+
}
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
// else... FALL THROUGH
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
case JSENUMERATE_DESTROY:
|
1213
|
+
default:
|
1214
|
+
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
1215
|
+
NS_IF_RELEASE(e);
|
1216
|
+
*statep = JSVAL_NULL;
|
1217
|
+
return NS_OK;
|
1218
|
+
}
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
static PRBool
|
1222
|
+
IsRegisteredCLSID(const char* str)
|
1223
|
+
{
|
1224
|
+
PRBool registered;
|
1225
|
+
nsID id;
|
1226
|
+
|
1227
|
+
if(!id.Parse(str))
|
1228
|
+
return PR_FALSE;
|
1229
|
+
|
1230
|
+
nsCOMPtr<nsIComponentRegistrar> compMgr;
|
1231
|
+
if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr ||
|
1232
|
+
NS_FAILED(compMgr->IsCIDRegistered(id, ®istered)))
|
1233
|
+
return PR_FALSE;
|
1234
|
+
|
1235
|
+
return registered;
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
1239
|
+
NS_IMETHODIMP
|
1240
|
+
nsXPCComponents_ClassesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
1241
|
+
JSContext * cx, JSObject * obj,
|
1242
|
+
jsval id, PRUint32 flags,
|
1243
|
+
JSObject * *objp, PRBool *_retval)
|
1244
|
+
{
|
1245
|
+
const char* name = nsnull;
|
1246
|
+
|
1247
|
+
if(JSVAL_IS_STRING(id) &&
|
1248
|
+
nsnull != (name = JS_GetStringBytes(JSVAL_TO_STRING(id))) &&
|
1249
|
+
name[0] == '{' &&
|
1250
|
+
IsRegisteredCLSID(name)) // we only allow canonical CLSIDs here
|
1251
|
+
{
|
1252
|
+
nsCOMPtr<nsIJSCID> nsid =
|
1253
|
+
dont_AddRef(static_cast<nsIJSCID*>(nsJSCID::NewID(name)));
|
1254
|
+
if(nsid)
|
1255
|
+
{
|
1256
|
+
nsCOMPtr<nsIXPConnect> xpc;
|
1257
|
+
wrapper->GetXPConnect(getter_AddRefs(xpc));
|
1258
|
+
if(xpc)
|
1259
|
+
{
|
1260
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
1261
|
+
if(NS_SUCCEEDED(xpc->WrapNative(cx, obj,
|
1262
|
+
static_cast<nsIJSCID*>(nsid),
|
1263
|
+
NS_GET_IID(nsIJSCID),
|
1264
|
+
getter_AddRefs(holder))))
|
1265
|
+
{
|
1266
|
+
JSObject* idobj;
|
1267
|
+
if(holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
|
1268
|
+
{
|
1269
|
+
jsid idid;
|
1270
|
+
|
1271
|
+
*objp = obj;
|
1272
|
+
*_retval = JS_ValueToId(cx, id, &idid) &&
|
1273
|
+
JS_DefinePropertyById(cx, obj, idid,
|
1274
|
+
OBJECT_TO_JSVAL(idobj),
|
1275
|
+
nsnull, nsnull,
|
1276
|
+
JSPROP_ENUMERATE |
|
1277
|
+
JSPROP_READONLY |
|
1278
|
+
JSPROP_PERMANENT);
|
1279
|
+
}
|
1280
|
+
}
|
1281
|
+
}
|
1282
|
+
}
|
1283
|
+
}
|
1284
|
+
return NS_OK;
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
|
1288
|
+
/***************************************************************************/
|
1289
|
+
|
1290
|
+
// Currently the possible results do not change at runtime, so they are only
|
1291
|
+
// cached once (unlike ContractIDs, CLSIDs, and IIDs)
|
1292
|
+
|
1293
|
+
class nsXPCComponents_Results :
|
1294
|
+
public nsIXPCComponents_Results,
|
1295
|
+
public nsIXPCScriptable,
|
1296
|
+
public nsIClassInfo
|
1297
|
+
{
|
1298
|
+
public:
|
1299
|
+
// all the interface method declarations...
|
1300
|
+
NS_DECL_ISUPPORTS
|
1301
|
+
NS_DECL_NSIXPCCOMPONENTS_RESULTS
|
1302
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
1303
|
+
NS_DECL_NSICLASSINFO
|
1304
|
+
|
1305
|
+
public:
|
1306
|
+
nsXPCComponents_Results();
|
1307
|
+
virtual ~nsXPCComponents_Results();
|
1308
|
+
};
|
1309
|
+
|
1310
|
+
/***************************************************************************/
|
1311
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
1312
|
+
out nsIIDPtr array); */
|
1313
|
+
NS_IMETHODIMP
|
1314
|
+
nsXPCComponents_Results::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
1315
|
+
{
|
1316
|
+
PRUint32 count = 2;
|
1317
|
+
*aCount = count;
|
1318
|
+
nsIID **array;
|
1319
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
1320
|
+
if(!array)
|
1321
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1322
|
+
|
1323
|
+
PRUint32 index = 0;
|
1324
|
+
nsIID* clone;
|
1325
|
+
#define PUSH_IID(id) \
|
1326
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
1327
|
+
sizeof(nsIID))); \
|
1328
|
+
if (!clone) \
|
1329
|
+
goto oom; \
|
1330
|
+
array[index++] = clone;
|
1331
|
+
|
1332
|
+
PUSH_IID(nsIXPCComponents_Results)
|
1333
|
+
PUSH_IID(nsIXPCScriptable)
|
1334
|
+
#undef PUSH_IID
|
1335
|
+
|
1336
|
+
return NS_OK;
|
1337
|
+
oom:
|
1338
|
+
while (index)
|
1339
|
+
nsMemory::Free(array[--index]);
|
1340
|
+
nsMemory::Free(array);
|
1341
|
+
*aArray = nsnull;
|
1342
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1343
|
+
}
|
1344
|
+
|
1345
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
1346
|
+
NS_IMETHODIMP
|
1347
|
+
nsXPCComponents_Results::GetHelperForLanguage(PRUint32 language,
|
1348
|
+
nsISupports **retval)
|
1349
|
+
{
|
1350
|
+
*retval = nsnull;
|
1351
|
+
return NS_OK;
|
1352
|
+
}
|
1353
|
+
|
1354
|
+
/* readonly attribute string contractID; */
|
1355
|
+
NS_IMETHODIMP
|
1356
|
+
nsXPCComponents_Results::GetContractID(char * *aContractID)
|
1357
|
+
{
|
1358
|
+
*aContractID = nsnull;
|
1359
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1360
|
+
}
|
1361
|
+
|
1362
|
+
/* readonly attribute string classDescription; */
|
1363
|
+
NS_IMETHODIMP
|
1364
|
+
nsXPCComponents_Results::GetClassDescription(char * *aClassDescription)
|
1365
|
+
{
|
1366
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
1367
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
1368
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1369
|
+
}
|
1370
|
+
|
1371
|
+
/* readonly attribute nsCIDPtr classID; */
|
1372
|
+
NS_IMETHODIMP
|
1373
|
+
nsXPCComponents_Results::GetClassID(nsCID * *aClassID)
|
1374
|
+
{
|
1375
|
+
*aClassID = nsnull;
|
1376
|
+
return NS_OK;
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
1380
|
+
NS_IMETHODIMP
|
1381
|
+
nsXPCComponents_Results::GetImplementationLanguage(
|
1382
|
+
PRUint32 *aImplementationLanguage)
|
1383
|
+
{
|
1384
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
1385
|
+
return NS_OK;
|
1386
|
+
}
|
1387
|
+
|
1388
|
+
/* readonly attribute PRUint32 flags; */
|
1389
|
+
NS_IMETHODIMP
|
1390
|
+
nsXPCComponents_Results::GetFlags(PRUint32 *aFlags)
|
1391
|
+
{
|
1392
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
1393
|
+
return NS_OK;
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
1397
|
+
NS_IMETHODIMP
|
1398
|
+
nsXPCComponents_Results::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
1399
|
+
{
|
1400
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
nsXPCComponents_Results::nsXPCComponents_Results()
|
1404
|
+
{
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
nsXPCComponents_Results::~nsXPCComponents_Results()
|
1408
|
+
{
|
1409
|
+
// empty
|
1410
|
+
}
|
1411
|
+
|
1412
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Results)
|
1413
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Results)
|
1414
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
1415
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
1416
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Results)
|
1417
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
1418
|
+
|
1419
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Results)
|
1420
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Results)
|
1421
|
+
|
1422
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
1423
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Results
|
1424
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Results"
|
1425
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
1426
|
+
#define XPC_MAP_WANT_NEWENUMERATE
|
1427
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |\
|
1428
|
+
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
1429
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
1430
|
+
|
1431
|
+
/* PRBool newEnumerate (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); */
|
1432
|
+
NS_IMETHODIMP
|
1433
|
+
nsXPCComponents_Results::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
1434
|
+
JSContext * cx, JSObject * obj,
|
1435
|
+
PRUint32 enum_op, jsval * statep,
|
1436
|
+
jsid * idp, PRBool *_retval)
|
1437
|
+
{
|
1438
|
+
void** iter;
|
1439
|
+
|
1440
|
+
switch(enum_op)
|
1441
|
+
{
|
1442
|
+
case JSENUMERATE_INIT:
|
1443
|
+
{
|
1444
|
+
if(idp)
|
1445
|
+
*idp = INT_TO_JSVAL(nsXPCException::GetNSResultCount());
|
1446
|
+
|
1447
|
+
void** space = (void**) new char[sizeof(void*)];
|
1448
|
+
*space = nsnull;
|
1449
|
+
*statep = PRIVATE_TO_JSVAL(space);
|
1450
|
+
return NS_OK;
|
1451
|
+
}
|
1452
|
+
case JSENUMERATE_NEXT:
|
1453
|
+
{
|
1454
|
+
const char* name;
|
1455
|
+
iter = (void**) JSVAL_TO_PRIVATE(*statep);
|
1456
|
+
if(nsXPCException::IterateNSResults(nsnull, &name, nsnull, iter))
|
1457
|
+
{
|
1458
|
+
JSString* idstr = JS_NewStringCopyZ(cx, name);
|
1459
|
+
if(idstr && JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
|
1460
|
+
return NS_OK;
|
1461
|
+
}
|
1462
|
+
// else... FALL THROUGH
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
case JSENUMERATE_DESTROY:
|
1466
|
+
default:
|
1467
|
+
iter = (void**) JSVAL_TO_PRIVATE(*statep);
|
1468
|
+
delete [] (char*) iter;
|
1469
|
+
*statep = JSVAL_NULL;
|
1470
|
+
return NS_OK;
|
1471
|
+
}
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
|
1475
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
1476
|
+
NS_IMETHODIMP
|
1477
|
+
nsXPCComponents_Results::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
1478
|
+
JSContext * cx, JSObject * obj,
|
1479
|
+
jsval id, PRUint32 flags,
|
1480
|
+
JSObject * *objp, PRBool *_retval)
|
1481
|
+
{
|
1482
|
+
const char* name = nsnull;
|
1483
|
+
|
1484
|
+
if(JSVAL_IS_STRING(id) &&
|
1485
|
+
nsnull != (name = JS_GetStringBytes(JSVAL_TO_STRING(id))))
|
1486
|
+
{
|
1487
|
+
const char* rv_name;
|
1488
|
+
void* iter = nsnull;
|
1489
|
+
nsresult rv;
|
1490
|
+
while(nsXPCException::IterateNSResults(&rv, &rv_name, nsnull, &iter))
|
1491
|
+
{
|
1492
|
+
if(!strcmp(name, rv_name))
|
1493
|
+
{
|
1494
|
+
jsid idid;
|
1495
|
+
jsval val;
|
1496
|
+
|
1497
|
+
*objp = obj;
|
1498
|
+
if(!JS_NewNumberValue(cx, (jsdouble)rv, &val) ||
|
1499
|
+
!JS_ValueToId(cx, id, &idid) ||
|
1500
|
+
!JS_DefinePropertyById(cx, obj, idid, val,
|
1501
|
+
nsnull, nsnull,
|
1502
|
+
JSPROP_ENUMERATE |
|
1503
|
+
JSPROP_READONLY |
|
1504
|
+
JSPROP_PERMANENT))
|
1505
|
+
{
|
1506
|
+
return NS_ERROR_UNEXPECTED;
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
}
|
1511
|
+
return NS_OK;
|
1512
|
+
}
|
1513
|
+
|
1514
|
+
/***************************************************************************/
|
1515
|
+
// JavaScript Constructor for nsIJSID objects (Components.ID)
|
1516
|
+
|
1517
|
+
class nsXPCComponents_ID :
|
1518
|
+
public nsIXPCComponents_ID,
|
1519
|
+
public nsIXPCScriptable,
|
1520
|
+
public nsIClassInfo
|
1521
|
+
{
|
1522
|
+
public:
|
1523
|
+
// all the interface method declarations...
|
1524
|
+
NS_DECL_ISUPPORTS
|
1525
|
+
NS_DECL_NSIXPCCOMPONENTS_ID
|
1526
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
1527
|
+
NS_DECL_NSICLASSINFO
|
1528
|
+
|
1529
|
+
|
1530
|
+
public:
|
1531
|
+
nsXPCComponents_ID();
|
1532
|
+
virtual ~nsXPCComponents_ID();
|
1533
|
+
|
1534
|
+
private:
|
1535
|
+
NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
1536
|
+
JSContext * cx, JSObject * obj,
|
1537
|
+
PRUint32 argc, jsval * argv,
|
1538
|
+
jsval * vp, PRBool *_retval);
|
1539
|
+
};
|
1540
|
+
|
1541
|
+
/***************************************************************************/
|
1542
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
1543
|
+
out nsIIDPtr array); */
|
1544
|
+
NS_IMETHODIMP
|
1545
|
+
nsXPCComponents_ID::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
1546
|
+
{
|
1547
|
+
PRUint32 count = 2;
|
1548
|
+
*aCount = count;
|
1549
|
+
nsIID **array;
|
1550
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
1551
|
+
if(!array)
|
1552
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1553
|
+
|
1554
|
+
PRUint32 index = 0;
|
1555
|
+
nsIID* clone;
|
1556
|
+
#define PUSH_IID(id) \
|
1557
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
1558
|
+
sizeof(nsIID))); \
|
1559
|
+
if (!clone) \
|
1560
|
+
goto oom; \
|
1561
|
+
array[index++] = clone;
|
1562
|
+
|
1563
|
+
PUSH_IID(nsIXPCComponents_ID)
|
1564
|
+
PUSH_IID(nsIXPCScriptable)
|
1565
|
+
#undef PUSH_IID
|
1566
|
+
|
1567
|
+
return NS_OK;
|
1568
|
+
oom:
|
1569
|
+
while (index)
|
1570
|
+
nsMemory::Free(array[--index]);
|
1571
|
+
nsMemory::Free(array);
|
1572
|
+
*aArray = nsnull;
|
1573
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1574
|
+
}
|
1575
|
+
|
1576
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
1577
|
+
NS_IMETHODIMP
|
1578
|
+
nsXPCComponents_ID::GetHelperForLanguage(PRUint32 language,
|
1579
|
+
nsISupports **retval)
|
1580
|
+
{
|
1581
|
+
*retval = nsnull;
|
1582
|
+
return NS_OK;
|
1583
|
+
}
|
1584
|
+
|
1585
|
+
/* readonly attribute string contractID; */
|
1586
|
+
NS_IMETHODIMP
|
1587
|
+
nsXPCComponents_ID::GetContractID(char * *aContractID)
|
1588
|
+
{
|
1589
|
+
*aContractID = nsnull;
|
1590
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1591
|
+
}
|
1592
|
+
|
1593
|
+
/* readonly attribute string classDescription; */
|
1594
|
+
NS_IMETHODIMP
|
1595
|
+
nsXPCComponents_ID::GetClassDescription(char * *aClassDescription)
|
1596
|
+
{
|
1597
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
1598
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
1599
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1600
|
+
}
|
1601
|
+
|
1602
|
+
/* readonly attribute nsCIDPtr classID; */
|
1603
|
+
NS_IMETHODIMP
|
1604
|
+
nsXPCComponents_ID::GetClassID(nsCID * *aClassID)
|
1605
|
+
{
|
1606
|
+
*aClassID = nsnull;
|
1607
|
+
return NS_OK;
|
1608
|
+
}
|
1609
|
+
|
1610
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
1611
|
+
NS_IMETHODIMP
|
1612
|
+
nsXPCComponents_ID::GetImplementationLanguage(
|
1613
|
+
PRUint32 *aImplementationLanguage)
|
1614
|
+
{
|
1615
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
1616
|
+
return NS_OK;
|
1617
|
+
}
|
1618
|
+
|
1619
|
+
/* readonly attribute PRUint32 flags; */
|
1620
|
+
NS_IMETHODIMP
|
1621
|
+
nsXPCComponents_ID::GetFlags(PRUint32 *aFlags)
|
1622
|
+
{
|
1623
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
1624
|
+
return NS_OK;
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
1628
|
+
NS_IMETHODIMP
|
1629
|
+
nsXPCComponents_ID::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
1630
|
+
{
|
1631
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1632
|
+
}
|
1633
|
+
|
1634
|
+
nsXPCComponents_ID::nsXPCComponents_ID()
|
1635
|
+
{
|
1636
|
+
}
|
1637
|
+
|
1638
|
+
nsXPCComponents_ID::~nsXPCComponents_ID()
|
1639
|
+
{
|
1640
|
+
// empty
|
1641
|
+
}
|
1642
|
+
|
1643
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_ID)
|
1644
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_ID)
|
1645
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
1646
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
1647
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_ID)
|
1648
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
1649
|
+
|
1650
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_ID)
|
1651
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_ID)
|
1652
|
+
|
1653
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
1654
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_ID
|
1655
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_ID"
|
1656
|
+
#define XPC_MAP_WANT_CALL
|
1657
|
+
#define XPC_MAP_WANT_CONSTRUCT
|
1658
|
+
#define XPC_MAP_WANT_HASINSTANCE
|
1659
|
+
#define XPC_MAP_FLAGS 0
|
1660
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
1661
|
+
|
1662
|
+
|
1663
|
+
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
1664
|
+
NS_IMETHODIMP
|
1665
|
+
nsXPCComponents_ID::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
1666
|
+
{
|
1667
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
1668
|
+
|
1669
|
+
}
|
1670
|
+
|
1671
|
+
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
1672
|
+
NS_IMETHODIMP
|
1673
|
+
nsXPCComponents_ID::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
1674
|
+
{
|
1675
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
1676
|
+
}
|
1677
|
+
|
1678
|
+
NS_METHOD
|
1679
|
+
nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
1680
|
+
JSContext * cx, JSObject * obj,
|
1681
|
+
PRUint32 argc, jsval * argv,
|
1682
|
+
jsval * vp, PRBool *_retval)
|
1683
|
+
{
|
1684
|
+
// make sure we have at least one arg
|
1685
|
+
|
1686
|
+
if(!argc)
|
1687
|
+
return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);
|
1688
|
+
|
1689
|
+
XPCCallContext ccx(JS_CALLER, cx);
|
1690
|
+
if(!ccx.IsValid())
|
1691
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
1692
|
+
|
1693
|
+
XPCContext* xpcc = ccx.GetXPCContext();
|
1694
|
+
|
1695
|
+
// Do the security check if necessary
|
1696
|
+
|
1697
|
+
nsIXPCSecurityManager* sm =
|
1698
|
+
xpcc->GetAppropriateSecurityManager(
|
1699
|
+
nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
|
1700
|
+
if(sm && NS_FAILED(sm->CanCreateInstance(cx, nsJSID::GetCID())))
|
1701
|
+
{
|
1702
|
+
// the security manager vetoed. It should have set an exception.
|
1703
|
+
*_retval = JS_FALSE;
|
1704
|
+
return NS_OK;
|
1705
|
+
}
|
1706
|
+
|
1707
|
+
// convert the first argument into a string and see if it looks like an id
|
1708
|
+
|
1709
|
+
JSString* jsstr;
|
1710
|
+
const char* str;
|
1711
|
+
nsID id;
|
1712
|
+
|
1713
|
+
if(!(jsstr = JS_ValueToString(cx, argv[0])) ||
|
1714
|
+
!(str = JS_GetStringBytes(jsstr)) ||
|
1715
|
+
! id.Parse(str))
|
1716
|
+
{
|
1717
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_ID_STRING, cx, _retval);
|
1718
|
+
}
|
1719
|
+
|
1720
|
+
// make the new object and return it.
|
1721
|
+
|
1722
|
+
JSObject* newobj = xpc_NewIDObject(cx, obj, id);
|
1723
|
+
|
1724
|
+
if(vp)
|
1725
|
+
*vp = OBJECT_TO_JSVAL(newobj);
|
1726
|
+
|
1727
|
+
return NS_OK;
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
1731
|
+
NS_IMETHODIMP
|
1732
|
+
nsXPCComponents_ID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
1733
|
+
JSContext * cx, JSObject * obj,
|
1734
|
+
jsval val, PRBool *bp, PRBool *_retval)
|
1735
|
+
{
|
1736
|
+
if(bp)
|
1737
|
+
*bp = JSValIsInterfaceOfType(cx, val, NS_GET_IID(nsIJSID));
|
1738
|
+
return NS_OK;
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
/***************************************************************************/
|
1742
|
+
// JavaScript Constructor for nsIXPCException objects (Components.Exception)
|
1743
|
+
|
1744
|
+
class nsXPCComponents_Exception :
|
1745
|
+
public nsIXPCComponents_Exception,
|
1746
|
+
public nsIXPCScriptable,
|
1747
|
+
public nsIClassInfo
|
1748
|
+
{
|
1749
|
+
public:
|
1750
|
+
// all the interface method declarations...
|
1751
|
+
NS_DECL_ISUPPORTS
|
1752
|
+
NS_DECL_NSIXPCCOMPONENTS_EXCEPTION
|
1753
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
1754
|
+
NS_DECL_NSICLASSINFO
|
1755
|
+
|
1756
|
+
|
1757
|
+
public:
|
1758
|
+
nsXPCComponents_Exception();
|
1759
|
+
virtual ~nsXPCComponents_Exception();
|
1760
|
+
|
1761
|
+
private:
|
1762
|
+
NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
1763
|
+
JSContext * cx, JSObject * obj,
|
1764
|
+
PRUint32 argc, jsval * argv,
|
1765
|
+
jsval * vp, PRBool *_retval);
|
1766
|
+
};
|
1767
|
+
|
1768
|
+
/***************************************************************************/
|
1769
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
1770
|
+
out nsIIDPtr array); */
|
1771
|
+
NS_IMETHODIMP
|
1772
|
+
nsXPCComponents_Exception::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
1773
|
+
{
|
1774
|
+
PRUint32 count = 2;
|
1775
|
+
*aCount = count;
|
1776
|
+
nsIID **array;
|
1777
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
1778
|
+
if(!array)
|
1779
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1780
|
+
|
1781
|
+
PRUint32 index = 0;
|
1782
|
+
nsIID* clone;
|
1783
|
+
#define PUSH_IID(id) \
|
1784
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
1785
|
+
sizeof(nsIID))); \
|
1786
|
+
if (!clone) \
|
1787
|
+
goto oom; \
|
1788
|
+
array[index++] = clone;
|
1789
|
+
|
1790
|
+
PUSH_IID(nsIXPCComponents_Exception)
|
1791
|
+
PUSH_IID(nsIXPCScriptable)
|
1792
|
+
#undef PUSH_IID
|
1793
|
+
|
1794
|
+
return NS_OK;
|
1795
|
+
oom:
|
1796
|
+
while (index)
|
1797
|
+
nsMemory::Free(array[--index]);
|
1798
|
+
nsMemory::Free(array);
|
1799
|
+
*aArray = nsnull;
|
1800
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
1804
|
+
NS_IMETHODIMP
|
1805
|
+
nsXPCComponents_Exception::GetHelperForLanguage(PRUint32 language,
|
1806
|
+
nsISupports **retval)
|
1807
|
+
{
|
1808
|
+
*retval = nsnull;
|
1809
|
+
return NS_OK;
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
/* readonly attribute string contractID; */
|
1813
|
+
NS_IMETHODIMP
|
1814
|
+
nsXPCComponents_Exception::GetContractID(char * *aContractID)
|
1815
|
+
{
|
1816
|
+
*aContractID = nsnull;
|
1817
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
/* readonly attribute string classDescription; */
|
1821
|
+
NS_IMETHODIMP
|
1822
|
+
nsXPCComponents_Exception::GetClassDescription(char * *aClassDescription)
|
1823
|
+
{
|
1824
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
1825
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
1826
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1827
|
+
}
|
1828
|
+
|
1829
|
+
/* readonly attribute nsCIDPtr classID; */
|
1830
|
+
NS_IMETHODIMP
|
1831
|
+
nsXPCComponents_Exception::GetClassID(nsCID * *aClassID)
|
1832
|
+
{
|
1833
|
+
*aClassID = nsnull;
|
1834
|
+
return NS_OK;
|
1835
|
+
}
|
1836
|
+
|
1837
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
1838
|
+
NS_IMETHODIMP
|
1839
|
+
nsXPCComponents_Exception::GetImplementationLanguage(
|
1840
|
+
PRUint32 *aImplementationLanguage)
|
1841
|
+
{
|
1842
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
1843
|
+
return NS_OK;
|
1844
|
+
}
|
1845
|
+
|
1846
|
+
/* readonly attribute PRUint32 flags; */
|
1847
|
+
NS_IMETHODIMP
|
1848
|
+
nsXPCComponents_Exception::GetFlags(PRUint32 *aFlags)
|
1849
|
+
{
|
1850
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
1851
|
+
return NS_OK;
|
1852
|
+
}
|
1853
|
+
|
1854
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
1855
|
+
NS_IMETHODIMP
|
1856
|
+
nsXPCComponents_Exception::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
1857
|
+
{
|
1858
|
+
return NS_ERROR_NOT_AVAILABLE;
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
nsXPCComponents_Exception::nsXPCComponents_Exception()
|
1862
|
+
{
|
1863
|
+
}
|
1864
|
+
|
1865
|
+
nsXPCComponents_Exception::~nsXPCComponents_Exception()
|
1866
|
+
{
|
1867
|
+
// empty
|
1868
|
+
}
|
1869
|
+
|
1870
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Exception)
|
1871
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Exception)
|
1872
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
1873
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
1874
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Exception)
|
1875
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
1876
|
+
|
1877
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Exception)
|
1878
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Exception)
|
1879
|
+
|
1880
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
1881
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Exception
|
1882
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Exception"
|
1883
|
+
#define XPC_MAP_WANT_CALL
|
1884
|
+
#define XPC_MAP_WANT_CONSTRUCT
|
1885
|
+
#define XPC_MAP_WANT_HASINSTANCE
|
1886
|
+
#define XPC_MAP_FLAGS 0
|
1887
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
1888
|
+
|
1889
|
+
|
1890
|
+
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
1891
|
+
NS_IMETHODIMP
|
1892
|
+
nsXPCComponents_Exception::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
1893
|
+
{
|
1894
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
1895
|
+
|
1896
|
+
}
|
1897
|
+
|
1898
|
+
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
1899
|
+
NS_IMETHODIMP
|
1900
|
+
nsXPCComponents_Exception::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
1901
|
+
{
|
1902
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
1903
|
+
}
|
1904
|
+
|
1905
|
+
NS_METHOD
|
1906
|
+
nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
1907
|
+
JSContext * cx, JSObject * obj,
|
1908
|
+
PRUint32 argc, jsval * argv,
|
1909
|
+
jsval * vp, PRBool *_retval)
|
1910
|
+
{
|
1911
|
+
XPCCallContext ccx(JS_CALLER, cx);
|
1912
|
+
if(!ccx.IsValid())
|
1913
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
1914
|
+
|
1915
|
+
nsXPConnect* xpc = ccx.GetXPConnect();
|
1916
|
+
XPCContext* xpcc = ccx.GetXPCContext();
|
1917
|
+
|
1918
|
+
// Do the security check if necessary
|
1919
|
+
|
1920
|
+
nsIXPCSecurityManager* sm =
|
1921
|
+
xpcc->GetAppropriateSecurityManager(
|
1922
|
+
nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
|
1923
|
+
if(sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCException::GetCID())))
|
1924
|
+
{
|
1925
|
+
// the security manager vetoed. It should have set an exception.
|
1926
|
+
*_retval = JS_FALSE;
|
1927
|
+
return NS_OK;
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
// initialization params for the exception object we will create
|
1931
|
+
const char* eMsg = "exception";
|
1932
|
+
nsresult eResult = NS_ERROR_FAILURE;
|
1933
|
+
nsCOMPtr<nsIStackFrame> eStack;
|
1934
|
+
nsCOMPtr<nsISupports> eData;
|
1935
|
+
|
1936
|
+
// all params are optional - grab any passed in
|
1937
|
+
switch(argc)
|
1938
|
+
{
|
1939
|
+
default: // more than 4 - ignore extra
|
1940
|
+
// ...fall through...
|
1941
|
+
case 4: // argv[3] is object for eData
|
1942
|
+
if(JSVAL_IS_NULL(argv[3]))
|
1943
|
+
{
|
1944
|
+
// do nothing, leave eData as null
|
1945
|
+
}
|
1946
|
+
else
|
1947
|
+
{
|
1948
|
+
if(JSVAL_IS_PRIMITIVE(argv[3]) ||
|
1949
|
+
NS_FAILED(xpc->WrapJS(cx, JSVAL_TO_OBJECT(argv[3]),
|
1950
|
+
NS_GET_IID(nsISupports),
|
1951
|
+
(void**)getter_AddRefs(eData))))
|
1952
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
1953
|
+
}
|
1954
|
+
// ...fall through...
|
1955
|
+
case 3: // argv[2] is object for eStack
|
1956
|
+
if(JSVAL_IS_NULL(argv[2]))
|
1957
|
+
{
|
1958
|
+
// do nothing, leave eStack as null
|
1959
|
+
}
|
1960
|
+
else
|
1961
|
+
{
|
1962
|
+
if(JSVAL_IS_PRIMITIVE(argv[2]) ||
|
1963
|
+
NS_FAILED(xpc->WrapJS(cx, JSVAL_TO_OBJECT(argv[2]),
|
1964
|
+
NS_GET_IID(nsIStackFrame),
|
1965
|
+
(void**)getter_AddRefs(eStack))))
|
1966
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
1967
|
+
}
|
1968
|
+
// fall through...
|
1969
|
+
case 2: // argv[1] is nsresult for eResult
|
1970
|
+
if(!JS_ValueToECMAInt32(cx, argv[1], (int32*) &eResult))
|
1971
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
1972
|
+
// ...fall through...
|
1973
|
+
case 1: // argv[0] is string for eMsg
|
1974
|
+
{
|
1975
|
+
JSString* str = JS_ValueToString(cx, argv[0]);
|
1976
|
+
if(!str || !(eMsg = JS_GetStringBytes(str)))
|
1977
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
1978
|
+
}
|
1979
|
+
// ...fall through...
|
1980
|
+
case 0: // this case required so that 'default' does not include zero.
|
1981
|
+
; // -- do nothing --
|
1982
|
+
}
|
1983
|
+
|
1984
|
+
nsCOMPtr<nsIException> e;
|
1985
|
+
nsXPCException::NewException(eMsg, eResult, eStack, eData, getter_AddRefs(e));
|
1986
|
+
if(!e)
|
1987
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
1988
|
+
|
1989
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
1990
|
+
JSObject* newObj = nsnull;
|
1991
|
+
|
1992
|
+
if(NS_FAILED(xpc->WrapNative(cx, obj, e, NS_GET_IID(nsIXPCException),
|
1993
|
+
getter_AddRefs(holder))) || !holder ||
|
1994
|
+
NS_FAILED(holder->GetJSObject(&newObj)) || !newObj)
|
1995
|
+
{
|
1996
|
+
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
|
1997
|
+
}
|
1998
|
+
|
1999
|
+
if(vp)
|
2000
|
+
*vp = OBJECT_TO_JSVAL(newObj);
|
2001
|
+
|
2002
|
+
return NS_OK;
|
2003
|
+
}
|
2004
|
+
|
2005
|
+
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
2006
|
+
NS_IMETHODIMP
|
2007
|
+
nsXPCComponents_Exception::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
2008
|
+
JSContext * cx, JSObject * obj,
|
2009
|
+
jsval val, PRBool *bp,
|
2010
|
+
PRBool *_retval)
|
2011
|
+
{
|
2012
|
+
if(bp)
|
2013
|
+
*bp = JSValIsInterfaceOfType(cx, val, NS_GET_IID(nsIException));
|
2014
|
+
return NS_OK;
|
2015
|
+
}
|
2016
|
+
|
2017
|
+
/***************************************************************************/
|
2018
|
+
// This class is for the thing returned by "new Component.Constructor".
|
2019
|
+
|
2020
|
+
// XXXjband we use this CID for security check, but security system can't see
|
2021
|
+
// it since it has no registed factory. Security really kicks in when we try
|
2022
|
+
// to build a wrapper around an instance.
|
2023
|
+
|
2024
|
+
// {B4A95150-E25A-11d3-8F61-0010A4E73D9A}
|
2025
|
+
#define NS_XPCCONSTRUCTOR_CID \
|
2026
|
+
{ 0xb4a95150, 0xe25a, 0x11d3, \
|
2027
|
+
{ 0x8f, 0x61, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a } }
|
2028
|
+
|
2029
|
+
class nsXPCConstructor :
|
2030
|
+
public nsIXPCConstructor,
|
2031
|
+
public nsIXPCScriptable,
|
2032
|
+
public nsIClassInfo
|
2033
|
+
{
|
2034
|
+
public:
|
2035
|
+
NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCCONSTRUCTOR_CID)
|
2036
|
+
public:
|
2037
|
+
// all the interface method declarations...
|
2038
|
+
NS_DECL_ISUPPORTS
|
2039
|
+
NS_DECL_NSIXPCCONSTRUCTOR
|
2040
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
2041
|
+
NS_DECL_NSICLASSINFO
|
2042
|
+
|
2043
|
+
public:
|
2044
|
+
nsXPCConstructor(); // not implemented
|
2045
|
+
nsXPCConstructor(nsIJSCID* aClassID,
|
2046
|
+
nsIJSIID* aInterfaceID,
|
2047
|
+
const char* aInitializer);
|
2048
|
+
virtual ~nsXPCConstructor();
|
2049
|
+
|
2050
|
+
private:
|
2051
|
+
NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
2052
|
+
JSContext * cx, JSObject * obj,
|
2053
|
+
PRUint32 argc, jsval * argv,
|
2054
|
+
jsval * vp, PRBool *_retval);
|
2055
|
+
private:
|
2056
|
+
nsIJSCID* mClassID;
|
2057
|
+
nsIJSIID* mInterfaceID;
|
2058
|
+
char* mInitializer;
|
2059
|
+
};
|
2060
|
+
|
2061
|
+
/***************************************************************************/
|
2062
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
2063
|
+
out nsIIDPtr array); */
|
2064
|
+
NS_IMETHODIMP
|
2065
|
+
nsXPCConstructor::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
2066
|
+
{
|
2067
|
+
PRUint32 count = 2;
|
2068
|
+
*aCount = count;
|
2069
|
+
nsIID **array;
|
2070
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
2071
|
+
if(!array)
|
2072
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
2073
|
+
|
2074
|
+
PRUint32 index = 0;
|
2075
|
+
nsIID* clone;
|
2076
|
+
#define PUSH_IID(id) \
|
2077
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
2078
|
+
sizeof(nsIID))); \
|
2079
|
+
if (!clone) \
|
2080
|
+
goto oom; \
|
2081
|
+
array[index++] = clone;
|
2082
|
+
|
2083
|
+
PUSH_IID(nsIXPCConstructor)
|
2084
|
+
PUSH_IID(nsIXPCScriptable)
|
2085
|
+
#undef PUSH_IID
|
2086
|
+
|
2087
|
+
return NS_OK;
|
2088
|
+
oom:
|
2089
|
+
while (index)
|
2090
|
+
nsMemory::Free(array[--index]);
|
2091
|
+
nsMemory::Free(array);
|
2092
|
+
*aArray = nsnull;
|
2093
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
2094
|
+
}
|
2095
|
+
|
2096
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
2097
|
+
NS_IMETHODIMP
|
2098
|
+
nsXPCConstructor::GetHelperForLanguage(PRUint32 language,
|
2099
|
+
nsISupports **retval)
|
2100
|
+
{
|
2101
|
+
*retval = nsnull;
|
2102
|
+
return NS_OK;
|
2103
|
+
}
|
2104
|
+
|
2105
|
+
/* readonly attribute string contractID; */
|
2106
|
+
NS_IMETHODIMP
|
2107
|
+
nsXPCConstructor::GetContractID(char * *aContractID)
|
2108
|
+
{
|
2109
|
+
*aContractID = nsnull;
|
2110
|
+
return NS_ERROR_NOT_AVAILABLE;
|
2111
|
+
}
|
2112
|
+
|
2113
|
+
/* readonly attribute string classDescription; */
|
2114
|
+
NS_IMETHODIMP
|
2115
|
+
nsXPCConstructor::GetClassDescription(char * *aClassDescription)
|
2116
|
+
{
|
2117
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
2118
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
2119
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
/* readonly attribute nsCIDPtr classID; */
|
2123
|
+
NS_IMETHODIMP
|
2124
|
+
nsXPCConstructor::GetClassID(nsCID * *aClassID)
|
2125
|
+
{
|
2126
|
+
*aClassID = nsnull;
|
2127
|
+
return NS_OK;
|
2128
|
+
}
|
2129
|
+
|
2130
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
2131
|
+
NS_IMETHODIMP
|
2132
|
+
nsXPCConstructor::GetImplementationLanguage(
|
2133
|
+
PRUint32 *aImplementationLanguage)
|
2134
|
+
{
|
2135
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
2136
|
+
return NS_OK;
|
2137
|
+
}
|
2138
|
+
|
2139
|
+
/* readonly attribute PRUint32 flags; */
|
2140
|
+
NS_IMETHODIMP
|
2141
|
+
nsXPCConstructor::GetFlags(PRUint32 *aFlags)
|
2142
|
+
{
|
2143
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
2144
|
+
return NS_OK;
|
2145
|
+
}
|
2146
|
+
|
2147
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
2148
|
+
NS_IMETHODIMP
|
2149
|
+
nsXPCConstructor::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
2150
|
+
{
|
2151
|
+
return NS_ERROR_NOT_AVAILABLE;
|
2152
|
+
}
|
2153
|
+
|
2154
|
+
nsXPCConstructor::nsXPCConstructor(nsIJSCID* aClassID,
|
2155
|
+
nsIJSIID* aInterfaceID,
|
2156
|
+
const char* aInitializer)
|
2157
|
+
{
|
2158
|
+
NS_IF_ADDREF(mClassID = aClassID);
|
2159
|
+
NS_IF_ADDREF(mInterfaceID = aInterfaceID);
|
2160
|
+
mInitializer = aInitializer ?
|
2161
|
+
(char*) nsMemory::Clone(aInitializer, strlen(aInitializer)+1) :
|
2162
|
+
nsnull;
|
2163
|
+
}
|
2164
|
+
|
2165
|
+
nsXPCConstructor::~nsXPCConstructor()
|
2166
|
+
{
|
2167
|
+
NS_IF_RELEASE(mClassID);
|
2168
|
+
NS_IF_RELEASE(mInterfaceID);
|
2169
|
+
if(mInitializer)
|
2170
|
+
nsMemory::Free(mInitializer);
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
/* readonly attribute nsIJSCID classID; */
|
2174
|
+
NS_IMETHODIMP
|
2175
|
+
nsXPCConstructor::GetClassID(nsIJSCID * *aClassID)
|
2176
|
+
{
|
2177
|
+
NS_IF_ADDREF(*aClassID = mClassID);
|
2178
|
+
return NS_OK;
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
/* readonly attribute nsIJSIID interfaceID; */
|
2182
|
+
NS_IMETHODIMP
|
2183
|
+
nsXPCConstructor::GetInterfaceID(nsIJSIID * *aInterfaceID)
|
2184
|
+
{
|
2185
|
+
NS_IF_ADDREF(*aInterfaceID = mInterfaceID);
|
2186
|
+
return NS_OK;
|
2187
|
+
}
|
2188
|
+
|
2189
|
+
/* readonly attribute string initializer; */
|
2190
|
+
NS_IMETHODIMP
|
2191
|
+
nsXPCConstructor::GetInitializer(char * *aInitializer)
|
2192
|
+
{
|
2193
|
+
XPC_STRING_GETTER_BODY(aInitializer, mInitializer);
|
2194
|
+
}
|
2195
|
+
|
2196
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCConstructor)
|
2197
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCConstructor)
|
2198
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
2199
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
2200
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCConstructor)
|
2201
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
2202
|
+
|
2203
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCConstructor)
|
2204
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCConstructor)
|
2205
|
+
|
2206
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
2207
|
+
#define XPC_MAP_CLASSNAME nsXPCConstructor
|
2208
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCConstructor"
|
2209
|
+
#define XPC_MAP_WANT_CALL
|
2210
|
+
#define XPC_MAP_WANT_CONSTRUCT
|
2211
|
+
#define XPC_MAP_FLAGS 0
|
2212
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
2213
|
+
|
2214
|
+
|
2215
|
+
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
2216
|
+
NS_IMETHODIMP
|
2217
|
+
nsXPCConstructor::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
2218
|
+
{
|
2219
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
2220
|
+
|
2221
|
+
}
|
2222
|
+
|
2223
|
+
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
2224
|
+
NS_IMETHODIMP
|
2225
|
+
nsXPCConstructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
2226
|
+
{
|
2227
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
2228
|
+
}
|
2229
|
+
|
2230
|
+
NS_METHOD
|
2231
|
+
nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
2232
|
+
JSContext * cx, JSObject * obj,
|
2233
|
+
PRUint32 argc, jsval * argv,
|
2234
|
+
jsval * vp, PRBool *_retval)
|
2235
|
+
{
|
2236
|
+
XPCCallContext ccx(JS_CALLER, cx);
|
2237
|
+
if(!ccx.IsValid())
|
2238
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2239
|
+
|
2240
|
+
nsXPConnect* xpc = ccx.GetXPConnect();
|
2241
|
+
|
2242
|
+
// security check not required because we are going to call through the
|
2243
|
+
// code which is reflected into JS which will do that for us later.
|
2244
|
+
|
2245
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> cidHolder;
|
2246
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> iidHolder;
|
2247
|
+
JSObject* cidObj;
|
2248
|
+
JSObject* iidObj;
|
2249
|
+
|
2250
|
+
if(NS_FAILED(xpc->WrapNative(cx, obj, mClassID, NS_GET_IID(nsIJSCID),
|
2251
|
+
getter_AddRefs(cidHolder))) || !cidHolder ||
|
2252
|
+
NS_FAILED(cidHolder->GetJSObject(&cidObj)) || !cidObj ||
|
2253
|
+
NS_FAILED(xpc->WrapNative(cx, obj, mInterfaceID, NS_GET_IID(nsIJSIID),
|
2254
|
+
getter_AddRefs(iidHolder))) || !iidHolder ||
|
2255
|
+
NS_FAILED(iidHolder->GetJSObject(&iidObj)) || !iidObj)
|
2256
|
+
{
|
2257
|
+
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
|
2258
|
+
}
|
2259
|
+
|
2260
|
+
jsval ctorArgs[1] = {OBJECT_TO_JSVAL(iidObj)};
|
2261
|
+
jsval val;
|
2262
|
+
|
2263
|
+
if(!JS_CallFunctionName(cx, cidObj, "createInstance", 1, ctorArgs, &val) ||
|
2264
|
+
JSVAL_IS_PRIMITIVE(val))
|
2265
|
+
{
|
2266
|
+
// createInstance will have thrown an exception
|
2267
|
+
*_retval = JS_FALSE;
|
2268
|
+
return NS_OK;
|
2269
|
+
}
|
2270
|
+
|
2271
|
+
// root the result
|
2272
|
+
if(vp)
|
2273
|
+
*vp = val;
|
2274
|
+
|
2275
|
+
// call initializer method if supplied
|
2276
|
+
if(mInitializer)
|
2277
|
+
{
|
2278
|
+
JSObject* newObj = JSVAL_TO_OBJECT(val);
|
2279
|
+
jsval fun;
|
2280
|
+
jsval ignored;
|
2281
|
+
|
2282
|
+
// first check existence of function property for better error reporting
|
2283
|
+
if(!JS_GetProperty(cx, newObj, mInitializer, &fun) ||
|
2284
|
+
JSVAL_IS_PRIMITIVE(fun))
|
2285
|
+
{
|
2286
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_INITIALIZER_NAME, cx, _retval);
|
2287
|
+
}
|
2288
|
+
|
2289
|
+
if(!JS_CallFunctionValue(cx, newObj, fun, argc, argv, &ignored))
|
2290
|
+
{
|
2291
|
+
// function should have thrown an exception
|
2292
|
+
*_retval = JS_FALSE;
|
2293
|
+
return NS_OK;
|
2294
|
+
}
|
2295
|
+
}
|
2296
|
+
|
2297
|
+
return NS_OK;
|
2298
|
+
}
|
2299
|
+
|
2300
|
+
/*******************************************************/
|
2301
|
+
// JavaScript Constructor for nsIXPCConstructor objects (Components.Constructor)
|
2302
|
+
|
2303
|
+
class nsXPCComponents_Constructor :
|
2304
|
+
public nsIXPCComponents_Constructor,
|
2305
|
+
public nsIXPCScriptable,
|
2306
|
+
public nsIClassInfo
|
2307
|
+
{
|
2308
|
+
public:
|
2309
|
+
// all the interface method declarations...
|
2310
|
+
NS_DECL_ISUPPORTS
|
2311
|
+
NS_DECL_NSIXPCCOMPONENTS_CONSTRUCTOR
|
2312
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
2313
|
+
NS_DECL_NSICLASSINFO
|
2314
|
+
|
2315
|
+
public:
|
2316
|
+
nsXPCComponents_Constructor();
|
2317
|
+
virtual ~nsXPCComponents_Constructor();
|
2318
|
+
|
2319
|
+
private:
|
2320
|
+
NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
2321
|
+
JSContext * cx, JSObject * obj,
|
2322
|
+
PRUint32 argc, jsval * argv,
|
2323
|
+
jsval * vp, PRBool *_retval);
|
2324
|
+
};
|
2325
|
+
|
2326
|
+
/***************************************************************************/
|
2327
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
2328
|
+
out nsIIDPtr array); */
|
2329
|
+
NS_IMETHODIMP
|
2330
|
+
nsXPCComponents_Constructor::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
2331
|
+
{
|
2332
|
+
PRUint32 count = 2;
|
2333
|
+
*aCount = count;
|
2334
|
+
nsIID **array;
|
2335
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
2336
|
+
if(!array)
|
2337
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
2338
|
+
|
2339
|
+
PRUint32 index = 0;
|
2340
|
+
nsIID* clone;
|
2341
|
+
#define PUSH_IID(id) \
|
2342
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
2343
|
+
sizeof(nsIID))); \
|
2344
|
+
if (!clone) \
|
2345
|
+
goto oom; \
|
2346
|
+
array[index++] = clone;
|
2347
|
+
|
2348
|
+
PUSH_IID(nsIXPCComponents_Constructor)
|
2349
|
+
PUSH_IID(nsIXPCScriptable)
|
2350
|
+
#undef PUSH_IID
|
2351
|
+
|
2352
|
+
return NS_OK;
|
2353
|
+
oom:
|
2354
|
+
while (index)
|
2355
|
+
nsMemory::Free(array[--index]);
|
2356
|
+
nsMemory::Free(array);
|
2357
|
+
*aArray = nsnull;
|
2358
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
2359
|
+
}
|
2360
|
+
|
2361
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
2362
|
+
NS_IMETHODIMP
|
2363
|
+
nsXPCComponents_Constructor::GetHelperForLanguage(PRUint32 language,
|
2364
|
+
nsISupports **retval)
|
2365
|
+
{
|
2366
|
+
*retval = nsnull;
|
2367
|
+
return NS_OK;
|
2368
|
+
}
|
2369
|
+
|
2370
|
+
/* readonly attribute string contractID; */
|
2371
|
+
NS_IMETHODIMP
|
2372
|
+
nsXPCComponents_Constructor::GetContractID(char * *aContractID)
|
2373
|
+
{
|
2374
|
+
*aContractID = nsnull;
|
2375
|
+
return NS_ERROR_NOT_AVAILABLE;
|
2376
|
+
}
|
2377
|
+
|
2378
|
+
/* readonly attribute string classDescription; */
|
2379
|
+
NS_IMETHODIMP
|
2380
|
+
nsXPCComponents_Constructor::GetClassDescription(char * *aClassDescription)
|
2381
|
+
{
|
2382
|
+
static const char classDescription[] = "XPCComponents_Interfaces";
|
2383
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
2384
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2385
|
+
}
|
2386
|
+
|
2387
|
+
/* readonly attribute nsCIDPtr classID; */
|
2388
|
+
NS_IMETHODIMP
|
2389
|
+
nsXPCComponents_Constructor::GetClassID(nsCID * *aClassID)
|
2390
|
+
{
|
2391
|
+
*aClassID = nsnull;
|
2392
|
+
return NS_OK;
|
2393
|
+
}
|
2394
|
+
|
2395
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
2396
|
+
NS_IMETHODIMP
|
2397
|
+
nsXPCComponents_Constructor::GetImplementationLanguage(
|
2398
|
+
PRUint32 *aImplementationLanguage)
|
2399
|
+
{
|
2400
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
2401
|
+
return NS_OK;
|
2402
|
+
}
|
2403
|
+
|
2404
|
+
/* readonly attribute PRUint32 flags; */
|
2405
|
+
NS_IMETHODIMP
|
2406
|
+
nsXPCComponents_Constructor::GetFlags(PRUint32 *aFlags)
|
2407
|
+
{
|
2408
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
2409
|
+
return NS_OK;
|
2410
|
+
}
|
2411
|
+
|
2412
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
2413
|
+
NS_IMETHODIMP
|
2414
|
+
nsXPCComponents_Constructor::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
2415
|
+
{
|
2416
|
+
return NS_ERROR_NOT_AVAILABLE;
|
2417
|
+
}
|
2418
|
+
|
2419
|
+
nsXPCComponents_Constructor::nsXPCComponents_Constructor()
|
2420
|
+
{
|
2421
|
+
}
|
2422
|
+
|
2423
|
+
nsXPCComponents_Constructor::~nsXPCComponents_Constructor()
|
2424
|
+
{
|
2425
|
+
// empty
|
2426
|
+
}
|
2427
|
+
|
2428
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Constructor)
|
2429
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Constructor)
|
2430
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
2431
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
2432
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Constructor)
|
2433
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
2434
|
+
|
2435
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Constructor)
|
2436
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Constructor)
|
2437
|
+
|
2438
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
2439
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Constructor
|
2440
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Constructor"
|
2441
|
+
#define XPC_MAP_WANT_CALL
|
2442
|
+
#define XPC_MAP_WANT_CONSTRUCT
|
2443
|
+
#define XPC_MAP_WANT_HASINSTANCE
|
2444
|
+
#define XPC_MAP_FLAGS 0
|
2445
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
2446
|
+
|
2447
|
+
|
2448
|
+
/* PRBool call (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
2449
|
+
NS_IMETHODIMP
|
2450
|
+
nsXPCComponents_Constructor::Call(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
2451
|
+
{
|
2452
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
2453
|
+
}
|
2454
|
+
|
2455
|
+
/* PRBool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
|
2456
|
+
NS_IMETHODIMP
|
2457
|
+
nsXPCComponents_Constructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, PRUint32 argc, jsval * argv, jsval * vp, PRBool *_retval)
|
2458
|
+
{
|
2459
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
2460
|
+
}
|
2461
|
+
|
2462
|
+
NS_METHOD
|
2463
|
+
nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
2464
|
+
JSContext * cx, JSObject * obj,
|
2465
|
+
PRUint32 argc, jsval * argv,
|
2466
|
+
jsval * vp, PRBool *_retval)
|
2467
|
+
{
|
2468
|
+
// make sure we have at least one arg
|
2469
|
+
|
2470
|
+
if(!argc)
|
2471
|
+
return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);
|
2472
|
+
|
2473
|
+
// get the various other object pointers we need
|
2474
|
+
|
2475
|
+
XPCCallContext ccx(JS_CALLER, cx);
|
2476
|
+
if(!ccx.IsValid())
|
2477
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2478
|
+
|
2479
|
+
nsXPConnect* xpc = ccx.GetXPConnect();
|
2480
|
+
XPCContext* xpcc = ccx.GetXPCContext();
|
2481
|
+
XPCWrappedNativeScope* scope =
|
2482
|
+
XPCWrappedNativeScope::FindInJSObjectScope(ccx, obj);
|
2483
|
+
nsXPCComponents* comp;
|
2484
|
+
|
2485
|
+
if(!xpc || !xpcc || !scope || !(comp = scope->GetComponents()))
|
2486
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2487
|
+
|
2488
|
+
// Do the security check if necessary
|
2489
|
+
|
2490
|
+
nsIXPCSecurityManager* sm =
|
2491
|
+
xpcc->GetAppropriateSecurityManager(
|
2492
|
+
nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
|
2493
|
+
if(sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCConstructor::GetCID())))
|
2494
|
+
{
|
2495
|
+
// the security manager vetoed. It should have set an exception.
|
2496
|
+
*_retval = JS_FALSE;
|
2497
|
+
return NS_OK;
|
2498
|
+
}
|
2499
|
+
|
2500
|
+
// initialization params for the Constructor object we will create
|
2501
|
+
nsCOMPtr<nsIJSCID> cClassID;
|
2502
|
+
nsCOMPtr<nsIJSIID> cInterfaceID;
|
2503
|
+
const char* cInitializer = nsnull;
|
2504
|
+
|
2505
|
+
if(argc >= 3)
|
2506
|
+
{
|
2507
|
+
// argv[2] is an initializer function or property name
|
2508
|
+
JSString* str = JS_ValueToString(cx, argv[2]);
|
2509
|
+
if(!str || !(cInitializer = JS_GetStringBytes(str)))
|
2510
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
2511
|
+
}
|
2512
|
+
|
2513
|
+
if(argc >= 2)
|
2514
|
+
{
|
2515
|
+
// argv[1] is an iid name string
|
2516
|
+
// XXXjband support passing "Components.interfaces.foo"?
|
2517
|
+
|
2518
|
+
nsCOMPtr<nsIScriptableInterfaces> ifaces;
|
2519
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
2520
|
+
JSObject* ifacesObj = nsnull;
|
2521
|
+
|
2522
|
+
// we do the lookup by asking the Components.interfaces object
|
2523
|
+
// for the property with this name - i.e. we let its caching of these
|
2524
|
+
// nsIJSIID objects work for us.
|
2525
|
+
|
2526
|
+
if(NS_FAILED(comp->GetInterfaces(getter_AddRefs(ifaces))) ||
|
2527
|
+
NS_FAILED(xpc->WrapNative(cx, obj, ifaces,
|
2528
|
+
NS_GET_IID(nsIScriptableInterfaces),
|
2529
|
+
getter_AddRefs(holder))) || !holder ||
|
2530
|
+
NS_FAILED(holder->GetJSObject(&ifacesObj)) || !ifacesObj)
|
2531
|
+
{
|
2532
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2533
|
+
}
|
2534
|
+
|
2535
|
+
JSString* str = JS_ValueToString(cx, argv[1]);
|
2536
|
+
if(!str)
|
2537
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
2538
|
+
|
2539
|
+
jsval val;
|
2540
|
+
if(!JS_GetProperty(cx, ifacesObj, JS_GetStringBytes(str), &val) ||
|
2541
|
+
JSVAL_IS_PRIMITIVE(val))
|
2542
|
+
{
|
2543
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_IID, cx, _retval);
|
2544
|
+
}
|
2545
|
+
|
2546
|
+
nsCOMPtr<nsIXPConnectWrappedNative> wn;
|
2547
|
+
if(NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(val),
|
2548
|
+
getter_AddRefs(wn))) || !wn ||
|
2549
|
+
!(cInterfaceID = do_QueryWrappedNative(wn)))
|
2550
|
+
{
|
2551
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2552
|
+
}
|
2553
|
+
}
|
2554
|
+
else
|
2555
|
+
{
|
2556
|
+
nsCOMPtr<nsIInterfaceInfo> info;
|
2557
|
+
xpc->GetInfoForIID(&NS_GET_IID(nsISupports), getter_AddRefs(info));
|
2558
|
+
|
2559
|
+
if(info)
|
2560
|
+
{
|
2561
|
+
cInterfaceID =
|
2562
|
+
dont_AddRef(
|
2563
|
+
static_cast<nsIJSIID*>(nsJSIID::NewID(info)));
|
2564
|
+
}
|
2565
|
+
if(!cInterfaceID)
|
2566
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2567
|
+
}
|
2568
|
+
|
2569
|
+
// a new scope to avoid warnings about shadowed names
|
2570
|
+
{
|
2571
|
+
// argv[0] is a contractid name string
|
2572
|
+
// XXXjband support passing "Components.classes.foo"?
|
2573
|
+
|
2574
|
+
// we do the lookup by asking the Components.classes object
|
2575
|
+
// for the property with this name - i.e. we let its caching of these
|
2576
|
+
// nsIJSCID objects work for us.
|
2577
|
+
|
2578
|
+
nsCOMPtr<nsIXPCComponents_Classes> classes;
|
2579
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
2580
|
+
JSObject* classesObj = nsnull;
|
2581
|
+
|
2582
|
+
if(NS_FAILED(comp->GetClasses(getter_AddRefs(classes))) ||
|
2583
|
+
NS_FAILED(xpc->WrapNative(cx, obj, classes,
|
2584
|
+
NS_GET_IID(nsIXPCComponents_Classes),
|
2585
|
+
getter_AddRefs(holder))) || !holder ||
|
2586
|
+
NS_FAILED(holder->GetJSObject(&classesObj)) || !classesObj)
|
2587
|
+
{
|
2588
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2589
|
+
}
|
2590
|
+
|
2591
|
+
JSString* str = JS_ValueToString(cx, argv[0]);
|
2592
|
+
if(!str)
|
2593
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
|
2594
|
+
|
2595
|
+
jsval val;
|
2596
|
+
if(!JS_GetProperty(cx, classesObj, JS_GetStringBytes(str), &val) ||
|
2597
|
+
JSVAL_IS_PRIMITIVE(val))
|
2598
|
+
{
|
2599
|
+
return ThrowAndFail(NS_ERROR_XPC_BAD_CID, cx, _retval);
|
2600
|
+
}
|
2601
|
+
|
2602
|
+
nsCOMPtr<nsIXPConnectWrappedNative> wn;
|
2603
|
+
if(NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(val),
|
2604
|
+
getter_AddRefs(wn))) || !wn ||
|
2605
|
+
!(cClassID = do_QueryWrappedNative(wn)))
|
2606
|
+
{
|
2607
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2608
|
+
}
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
nsCOMPtr<nsIXPCConstructor> ctor =
|
2612
|
+
static_cast<nsIXPCConstructor*>
|
2613
|
+
(new nsXPCConstructor(cClassID, cInterfaceID, cInitializer));
|
2614
|
+
if(!ctor)
|
2615
|
+
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
2616
|
+
|
2617
|
+
nsCOMPtr<nsIXPConnectJSObjectHolder> holder2;
|
2618
|
+
JSObject* newObj = nsnull;
|
2619
|
+
|
2620
|
+
if(NS_FAILED(xpc->WrapNative(cx, obj, ctor, NS_GET_IID(nsIXPCConstructor),
|
2621
|
+
getter_AddRefs(holder2))) || !holder2 ||
|
2622
|
+
NS_FAILED(holder2->GetJSObject(&newObj)) || !newObj)
|
2623
|
+
{
|
2624
|
+
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
|
2625
|
+
}
|
2626
|
+
|
2627
|
+
if(vp)
|
2628
|
+
*vp = OBJECT_TO_JSVAL(newObj);
|
2629
|
+
|
2630
|
+
return NS_OK;
|
2631
|
+
}
|
2632
|
+
|
2633
|
+
/* PRBool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal val, out PRBool bp); */
|
2634
|
+
NS_IMETHODIMP
|
2635
|
+
nsXPCComponents_Constructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
2636
|
+
JSContext * cx, JSObject * obj,
|
2637
|
+
jsval val, PRBool *bp,
|
2638
|
+
PRBool *_retval)
|
2639
|
+
{
|
2640
|
+
if(bp)
|
2641
|
+
*bp = JSValIsInterfaceOfType(cx, val, NS_GET_IID(nsIXPCConstructor));
|
2642
|
+
return NS_OK;
|
2643
|
+
}
|
2644
|
+
|
2645
|
+
/***************************************************************************/
|
2646
|
+
// Javascript constructor for the sandbox object
|
2647
|
+
class nsXPCComponents_utils_Sandbox : public nsIXPCComponents_utils_Sandbox,
|
2648
|
+
public nsIXPCScriptable
|
2649
|
+
{
|
2650
|
+
public:
|
2651
|
+
// Aren't macros nice?
|
2652
|
+
NS_DECL_ISUPPORTS
|
2653
|
+
NS_DECL_NSIXPCCOMPONENTS_UTILS_SANDBOX
|
2654
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
2655
|
+
|
2656
|
+
public:
|
2657
|
+
nsXPCComponents_utils_Sandbox();
|
2658
|
+
virtual ~nsXPCComponents_utils_Sandbox();
|
2659
|
+
|
2660
|
+
private:
|
2661
|
+
// XXXjst: This method (and other CallOrConstruct()'s in this
|
2662
|
+
// file) doesn't need to be virtual, could even be a static
|
2663
|
+
// method!
|
2664
|
+
NS_METHOD CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
2665
|
+
JSContext * cx, JSObject * obj,
|
2666
|
+
PRUint32 argc, jsval * argv,
|
2667
|
+
jsval * vp, PRBool *_retval);
|
2668
|
+
};
|
2669
|
+
|
2670
|
+
class nsXPCComponents_Utils :
|
2671
|
+
public nsIXPCComponents_Utils,
|
2672
|
+
public nsIXPCScriptable
|
2673
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
2674
|
+
, public nsISecurityCheckedComponent
|
2675
|
+
#endif
|
2676
|
+
{
|
2677
|
+
public:
|
2678
|
+
// all the interface method declarations...
|
2679
|
+
NS_DECL_ISUPPORTS
|
2680
|
+
NS_DECL_NSIXPCSCRIPTABLE
|
2681
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
2682
|
+
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
2683
|
+
#endif
|
2684
|
+
NS_DECL_NSIXPCCOMPONENTS_UTILS
|
2685
|
+
|
2686
|
+
public:
|
2687
|
+
nsXPCComponents_Utils() { }
|
2688
|
+
virtual ~nsXPCComponents_Utils() { }
|
2689
|
+
|
2690
|
+
private:
|
2691
|
+
nsCOMPtr<nsIXPCComponents_utils_Sandbox> mSandbox;
|
2692
|
+
};
|
2693
|
+
|
2694
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Utils)
|
2695
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Utils)
|
2696
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
2697
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
2698
|
+
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
|
2699
|
+
#endif
|
2700
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Utils)
|
2701
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
2702
|
+
|
2703
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Utils)
|
2704
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_Utils)
|
2705
|
+
|
2706
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
2707
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_Utils
|
2708
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_Utils"
|
2709
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
2710
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
2711
|
+
|
2712
|
+
NS_IMETHODIMP
|
2713
|
+
nsXPCComponents_Utils::GetSandbox(nsIXPCComponents_utils_Sandbox **aSandbox)
|
2714
|
+
{
|
2715
|
+
NS_ENSURE_ARG_POINTER(aSandbox);
|
2716
|
+
if (!mSandbox && !(mSandbox = new nsXPCComponents_utils_Sandbox())) {
|
2717
|
+
*aSandbox = nsnull;
|
2718
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
2719
|
+
}
|
2720
|
+
NS_ADDREF(*aSandbox = mSandbox);
|
2721
|
+
return NS_OK;
|
2722
|
+
}
|
2723
|
+
|
2724
|
+
static JSBool
|
2725
|
+
MethodWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
2726
|
+
jsval *rval)
|
2727
|
+
{
|
2728
|
+
jsval v;
|
2729
|
+
if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(argv[-2]), 0, &v) ||
|
2730
|
+
!JS_CallFunctionValue(cx, obj, v, argc, argv, rval)) {
|
2731
|
+
return JS_FALSE;
|
2732
|
+
}
|
2733
|
+
|
2734
|
+
if (JSVAL_IS_PRIMITIVE(*rval))
|
2735
|
+
return JS_TRUE;
|
2736
|
+
return XPCNativeWrapperCtor(cx, nsnull, 1, rval, rval);
|
2737
|
+
}
|
2738
|
+
|
2739
|
+
/* void lookupMethod (); */
|
2740
|
+
NS_IMETHODIMP
|
2741
|
+
nsXPCComponents_Utils::LookupMethod()
|
2742
|
+
{
|
2743
|
+
nsresult rv;
|
2744
|
+
|
2745
|
+
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
|
2746
|
+
if(NS_FAILED(rv))
|
2747
|
+
return NS_ERROR_FAILURE;
|
2748
|
+
|
2749
|
+
// get the xpconnect native call context
|
2750
|
+
nsAXPCNativeCallContext *cc = nsnull;
|
2751
|
+
xpc->GetCurrentNativeCallContext(&cc);
|
2752
|
+
if(!cc)
|
2753
|
+
return NS_ERROR_FAILURE;
|
2754
|
+
|
2755
|
+
// Check disabled until deprecated Components.lookupMethod removed.
|
2756
|
+
#undef CHECK_FOR_INDIRECT_CALL
|
2757
|
+
#ifdef CHECK_FOR_INDIRECT_CALL
|
2758
|
+
// verify that we are being called from JS (i.e. the current call is
|
2759
|
+
// to this object - though we don't verify that it is to this exact method)
|
2760
|
+
nsCOMPtr<nsISupports> callee;
|
2761
|
+
cc->GetCallee(getter_AddRefs(callee));
|
2762
|
+
if(!callee || callee.get() !=
|
2763
|
+
static_cast<const nsISupports*>
|
2764
|
+
(static_cast<const nsIXPCComponents_Utils*>(this)))
|
2765
|
+
return NS_ERROR_FAILURE;
|
2766
|
+
#endif
|
2767
|
+
|
2768
|
+
// Get JSContext of current call
|
2769
|
+
JSContext* cx;
|
2770
|
+
rv = cc->GetJSContext(&cx);
|
2771
|
+
if(NS_FAILED(rv) || !cx)
|
2772
|
+
return NS_ERROR_FAILURE;
|
2773
|
+
|
2774
|
+
JSAutoRequest ar(cx);
|
2775
|
+
|
2776
|
+
// get place for return value
|
2777
|
+
jsval *retval = nsnull;
|
2778
|
+
rv = cc->GetRetValPtr(&retval);
|
2779
|
+
if(NS_FAILED(rv) || !retval)
|
2780
|
+
return NS_ERROR_FAILURE;
|
2781
|
+
|
2782
|
+
// get argc and argv and verify arg count
|
2783
|
+
PRUint32 argc;
|
2784
|
+
rv = cc->GetArgc(&argc);
|
2785
|
+
if(NS_FAILED(rv))
|
2786
|
+
return NS_ERROR_FAILURE;
|
2787
|
+
|
2788
|
+
if(argc < 2)
|
2789
|
+
return NS_ERROR_XPC_NOT_ENOUGH_ARGS;
|
2790
|
+
|
2791
|
+
jsval* argv;
|
2792
|
+
rv = cc->GetArgvPtr(&argv);
|
2793
|
+
if(NS_FAILED(rv) || !argv)
|
2794
|
+
return NS_ERROR_FAILURE;
|
2795
|
+
|
2796
|
+
// first param must be a JSObject
|
2797
|
+
if(JSVAL_IS_PRIMITIVE(argv[0]))
|
2798
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2799
|
+
|
2800
|
+
JSObject* obj = JSVAL_TO_OBJECT(argv[0]);
|
2801
|
+
|
2802
|
+
OBJ_TO_INNER_OBJECT(cx, obj);
|
2803
|
+
|
2804
|
+
// second param must be a string
|
2805
|
+
if(!JSVAL_IS_STRING(argv[1]))
|
2806
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2807
|
+
|
2808
|
+
// Make sure the name (argv[1]) that we use for looking up the
|
2809
|
+
// method/property is atomized.
|
2810
|
+
|
2811
|
+
jsid name_id;
|
2812
|
+
if(!JS_ValueToId(cx, argv[1], &name_id) ||
|
2813
|
+
!JS_IdToValue(cx, name_id, &argv[1]))
|
2814
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2815
|
+
|
2816
|
+
// this will do verification and the method lookup for us
|
2817
|
+
// Note that if |obj| is an XPCNativeWrapper this will all still work.
|
2818
|
+
// We'll hand back the same method that we'd hand back for the underlying
|
2819
|
+
// XPCWrappedNative. This means no deep wrapping, unfortunately, but we
|
2820
|
+
// can't keep track of both the underlying function and the
|
2821
|
+
// XPCNativeWrapper at once in a single parent slot...
|
2822
|
+
XPCCallContext inner_cc(JS_CALLER, cx, obj, nsnull, argv[1]);
|
2823
|
+
|
2824
|
+
// was our jsobject really a wrapped native at all?
|
2825
|
+
XPCWrappedNative* wrapper = inner_cc.GetWrapper();
|
2826
|
+
if(!wrapper || !wrapper->IsValid())
|
2827
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2828
|
+
|
2829
|
+
// did we find a method/attribute by that name?
|
2830
|
+
XPCNativeMember* member = inner_cc.GetMember();
|
2831
|
+
if(!member || member->IsConstant())
|
2832
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2833
|
+
|
2834
|
+
// it would a be a big surprise if there is a member without an interface :)
|
2835
|
+
XPCNativeInterface* iface = inner_cc.GetInterface();
|
2836
|
+
if(!iface)
|
2837
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2838
|
+
|
2839
|
+
// get (and perhaps lazily create) the member's cloned function
|
2840
|
+
jsval funval;
|
2841
|
+
if(!member->NewFunctionObject(inner_cc, iface, wrapper->GetFlatJSObject(),
|
2842
|
+
&funval))
|
2843
|
+
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
2844
|
+
|
2845
|
+
// Stick the function in the return value. This roots it.
|
2846
|
+
*retval = funval;
|
2847
|
+
|
2848
|
+
// Callers of this method are implicitly buying into
|
2849
|
+
// XPCNativeWrapper-like protection. The easiest way
|
2850
|
+
// to enforce this is to use our own wrapper.
|
2851
|
+
// Note: We use the outer call context to ensure that we wrap
|
2852
|
+
// the function in the right scope.
|
2853
|
+
NS_ASSERTION(JSVAL_IS_OBJECT(funval), "Function is not an object");
|
2854
|
+
JSContext *outercx;
|
2855
|
+
cc->GetJSContext(&outercx);
|
2856
|
+
JSFunction *oldfunction = JS_ValueToFunction(outercx, funval);
|
2857
|
+
NS_ASSERTION(oldfunction, "Function is not a function");
|
2858
|
+
|
2859
|
+
JSFunction *f = JS_NewFunction(outercx, MethodWrapper,
|
2860
|
+
JS_GetFunctionArity(oldfunction), 0,
|
2861
|
+
JS_GetScopeChain(outercx),
|
2862
|
+
JS_GetFunctionName(oldfunction));
|
2863
|
+
if(!f)
|
2864
|
+
return NS_ERROR_FAILURE;
|
2865
|
+
|
2866
|
+
JSObject *funobj = JS_GetFunctionObject(f);
|
2867
|
+
if(!JS_SetReservedSlot(outercx, funobj, 0, funval))
|
2868
|
+
return NS_ERROR_FAILURE;
|
2869
|
+
|
2870
|
+
*retval = OBJECT_TO_JSVAL(funobj);
|
2871
|
+
|
2872
|
+
// Tell XPConnect that we returned the function through the call context.
|
2873
|
+
cc->SetReturnValueWasSet(PR_TRUE);
|
2874
|
+
return NS_OK;
|
2875
|
+
}
|
2876
|
+
|
2877
|
+
/* void reportError (); */
|
2878
|
+
NS_IMETHODIMP
|
2879
|
+
nsXPCComponents_Utils::ReportError()
|
2880
|
+
{
|
2881
|
+
// This function shall never fail! Silently eat any failure conditions.
|
2882
|
+
nsresult rv;
|
2883
|
+
|
2884
|
+
nsCOMPtr<nsIConsoleService> console(
|
2885
|
+
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
2886
|
+
|
2887
|
+
nsCOMPtr<nsIScriptError> scripterr(new nsScriptError());
|
2888
|
+
|
2889
|
+
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
|
2890
|
+
if(!scripterr || !console || !xpc)
|
2891
|
+
return NS_OK;
|
2892
|
+
|
2893
|
+
// get the xpconnect native call context
|
2894
|
+
nsAXPCNativeCallContext *cc = nsnull;
|
2895
|
+
xpc->GetCurrentNativeCallContext(&cc);
|
2896
|
+
if(!cc)
|
2897
|
+
return NS_OK;
|
2898
|
+
|
2899
|
+
// Check disabled until deprecated Components.reportError removed.
|
2900
|
+
#undef CHECK_FOR_INDIRECT_CALL
|
2901
|
+
#ifdef CHECK_FOR_INDIRECT_CALL
|
2902
|
+
// verify that we are being called from JS (i.e. the current call is
|
2903
|
+
// to this object - though we don't verify that it is to this exact method)
|
2904
|
+
nsCOMPtr<nsISupports> callee;
|
2905
|
+
cc->GetCallee(getter_AddRefs(callee));
|
2906
|
+
if(!callee || callee.get() !=
|
2907
|
+
static_cast<const nsISupports*>
|
2908
|
+
(static_cast<const nsIXPCComponents_Utils*>(this))) {
|
2909
|
+
NS_ERROR("reportError() must only be called from JS!");
|
2910
|
+
return NS_ERROR_FAILURE;
|
2911
|
+
}
|
2912
|
+
#endif
|
2913
|
+
|
2914
|
+
// Get JSContext of current call
|
2915
|
+
JSContext* cx;
|
2916
|
+
rv = cc->GetJSContext(&cx);
|
2917
|
+
if(NS_FAILED(rv) || !cx)
|
2918
|
+
return NS_OK;
|
2919
|
+
|
2920
|
+
JSAutoRequest ar(cx);
|
2921
|
+
|
2922
|
+
// get argc and argv and verify arg count
|
2923
|
+
PRUint32 argc;
|
2924
|
+
rv = cc->GetArgc(&argc);
|
2925
|
+
if(NS_FAILED(rv))
|
2926
|
+
return NS_OK;
|
2927
|
+
|
2928
|
+
if(argc < 1)
|
2929
|
+
return NS_ERROR_XPC_NOT_ENOUGH_ARGS;
|
2930
|
+
|
2931
|
+
jsval* argv;
|
2932
|
+
rv = cc->GetArgvPtr(&argv);
|
2933
|
+
if(NS_FAILED(rv) || !argv)
|
2934
|
+
return NS_OK;
|
2935
|
+
|
2936
|
+
JSErrorReport* err = JS_ErrorFromException(cx, argv[0]);
|
2937
|
+
if(err)
|
2938
|
+
{
|
2939
|
+
// It's a proper JS Error
|
2940
|
+
nsAutoString fileUni;
|
2941
|
+
CopyUTF8toUTF16(err->filename, fileUni);
|
2942
|
+
|
2943
|
+
PRUint32 column = err->uctokenptr - err->uclinebuf;
|
2944
|
+
|
2945
|
+
rv = scripterr->Init(reinterpret_cast<const PRUnichar*>
|
2946
|
+
(err->ucmessage),
|
2947
|
+
fileUni.get(),
|
2948
|
+
reinterpret_cast<const PRUnichar*>
|
2949
|
+
(err->uclinebuf),
|
2950
|
+
err->lineno,
|
2951
|
+
column,
|
2952
|
+
err->flags,
|
2953
|
+
"XPConnect JavaScript");
|
2954
|
+
if(NS_FAILED(rv))
|
2955
|
+
return NS_OK;
|
2956
|
+
|
2957
|
+
console->LogMessage(scripterr);
|
2958
|
+
return NS_OK;
|
2959
|
+
}
|
2960
|
+
|
2961
|
+
// It's not a JS Error object, so we synthesize as best we're able
|
2962
|
+
JSString* msgstr = JS_ValueToString(cx, argv[0]);
|
2963
|
+
if(msgstr)
|
2964
|
+
{
|
2965
|
+
// Root the string during scripterr->Init
|
2966
|
+
argv[0] = STRING_TO_JSVAL(msgstr);
|
2967
|
+
|
2968
|
+
nsCOMPtr<nsIStackFrame> frame;
|
2969
|
+
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
2970
|
+
if(xpc)
|
2971
|
+
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
2972
|
+
|
2973
|
+
nsXPIDLCString fileName;
|
2974
|
+
PRInt32 lineNo = 0;
|
2975
|
+
if(frame)
|
2976
|
+
{
|
2977
|
+
frame->GetFilename(getter_Copies(fileName));
|
2978
|
+
frame->GetLineNumber(&lineNo);
|
2979
|
+
}
|
2980
|
+
|
2981
|
+
rv = scripterr->Init(reinterpret_cast<const PRUnichar*>
|
2982
|
+
(JS_GetStringChars(msgstr)),
|
2983
|
+
NS_ConvertUTF8toUTF16(fileName).get(),
|
2984
|
+
nsnull,
|
2985
|
+
lineNo, 0,
|
2986
|
+
0, "XPConnect JavaScript");
|
2987
|
+
if(NS_SUCCEEDED(rv))
|
2988
|
+
console->LogMessage(scripterr);
|
2989
|
+
}
|
2990
|
+
|
2991
|
+
return NS_OK;
|
2992
|
+
}
|
2993
|
+
|
2994
|
+
#ifndef XPCONNECT_STANDALONE
|
2995
|
+
#include "nsIScriptSecurityManager.h"
|
2996
|
+
#include "nsIURI.h"
|
2997
|
+
#include "nsNetUtil.h"
|
2998
|
+
const char kScriptSecurityManagerContractID[] = NS_SCRIPTSECURITYMANAGER_CONTRACTID;
|
2999
|
+
|
3000
|
+
NS_IMPL_THREADSAFE_ISUPPORTS1(PrincipalHolder, nsIScriptObjectPrincipal)
|
3001
|
+
|
3002
|
+
nsIPrincipal *
|
3003
|
+
PrincipalHolder::GetPrincipal()
|
3004
|
+
{
|
3005
|
+
return mHoldee;
|
3006
|
+
}
|
3007
|
+
|
3008
|
+
static JSBool
|
3009
|
+
SandboxDump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
3010
|
+
{
|
3011
|
+
JSString *str;
|
3012
|
+
if (!argc)
|
3013
|
+
return JS_TRUE;
|
3014
|
+
|
3015
|
+
str = JS_ValueToString(cx, argv[0]);
|
3016
|
+
if (!str)
|
3017
|
+
return JS_FALSE;
|
3018
|
+
|
3019
|
+
char *bytes = JS_GetStringBytes(str);
|
3020
|
+
if (!bytes)
|
3021
|
+
return JS_FALSE;
|
3022
|
+
|
3023
|
+
fputs(bytes, stderr);
|
3024
|
+
return JS_TRUE;
|
3025
|
+
}
|
3026
|
+
|
3027
|
+
static JSBool
|
3028
|
+
SandboxDebug(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
3029
|
+
{
|
3030
|
+
#ifdef DEBUG
|
3031
|
+
return SandboxDump(cx, obj, argc, argv, rval);
|
3032
|
+
#else
|
3033
|
+
return JS_TRUE;
|
3034
|
+
#endif
|
3035
|
+
}
|
3036
|
+
|
3037
|
+
static JSBool
|
3038
|
+
SandboxFunForwarder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
3039
|
+
jsval *rval)
|
3040
|
+
{
|
3041
|
+
jsval v;
|
3042
|
+
if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(argv[-2]), 0, &v) ||
|
3043
|
+
!JS_CallFunctionValue(cx, obj, v, argc, argv, rval)) {
|
3044
|
+
return JS_FALSE;
|
3045
|
+
}
|
3046
|
+
|
3047
|
+
if (JSVAL_IS_PRIMITIVE(*rval))
|
3048
|
+
return JS_TRUE; // nothing more to do.
|
3049
|
+
|
3050
|
+
XPCThrower::Throw(NS_ERROR_NOT_IMPLEMENTED, cx);
|
3051
|
+
return JS_FALSE;
|
3052
|
+
}
|
3053
|
+
|
3054
|
+
static JSBool
|
3055
|
+
SandboxImport(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
3056
|
+
jsval *rval)
|
3057
|
+
{
|
3058
|
+
if (argc < 1) {
|
3059
|
+
XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);
|
3060
|
+
return JS_FALSE;
|
3061
|
+
}
|
3062
|
+
|
3063
|
+
JSFunction *fun = JS_ValueToFunction(cx, argv[0]);
|
3064
|
+
if (!fun) {
|
3065
|
+
XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);
|
3066
|
+
return JS_FALSE;
|
3067
|
+
}
|
3068
|
+
|
3069
|
+
JSString *funname;
|
3070
|
+
if (argc > 1) {
|
3071
|
+
// Use the second parameter as the function name.
|
3072
|
+
funname = JS_ValueToString(cx, argv[1]);
|
3073
|
+
if (!funname)
|
3074
|
+
return JS_FALSE;
|
3075
|
+
argv[1] = STRING_TO_JSVAL(funname);
|
3076
|
+
} else {
|
3077
|
+
// Use the actual function name as the name.
|
3078
|
+
funname = JS_GetFunctionId(fun);
|
3079
|
+
if (!funname) {
|
3080
|
+
XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);
|
3081
|
+
return JS_FALSE;
|
3082
|
+
}
|
3083
|
+
}
|
3084
|
+
|
3085
|
+
nsresult rv = NS_ERROR_FAILURE;
|
3086
|
+
JSObject *oldfunobj = JS_GetFunctionObject(fun);
|
3087
|
+
nsXPConnect *xpc = nsXPConnect::GetXPConnect();
|
3088
|
+
|
3089
|
+
if (xpc && oldfunobj) {
|
3090
|
+
nsIXPCSecurityManager *secman = xpc->GetDefaultSecurityManager();
|
3091
|
+
if (secman) {
|
3092
|
+
rv = secman->CanAccess(nsIXPCSecurityManager::ACCESS_CALL_METHOD,
|
3093
|
+
nsnull, cx, oldfunobj, nsnull, nsnull,
|
3094
|
+
STRING_TO_JSVAL(funname), nsnull);
|
3095
|
+
}
|
3096
|
+
}
|
3097
|
+
|
3098
|
+
if (NS_FAILED(rv)) {
|
3099
|
+
if (rv == NS_ERROR_FAILURE)
|
3100
|
+
XPCThrower::Throw(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx);
|
3101
|
+
return JS_FALSE;
|
3102
|
+
}
|
3103
|
+
|
3104
|
+
JSFunction *newfun = JS_DefineUCFunction(cx, obj,
|
3105
|
+
JS_GetStringChars(funname), JS_GetStringLength(funname),
|
3106
|
+
SandboxFunForwarder, JS_GetFunctionArity(fun), 0);
|
3107
|
+
|
3108
|
+
if (!newfun)
|
3109
|
+
return JS_FALSE;
|
3110
|
+
|
3111
|
+
JSObject *newfunobj = JS_GetFunctionObject(newfun);
|
3112
|
+
if (!newfunobj)
|
3113
|
+
return JS_FALSE;
|
3114
|
+
|
3115
|
+
// Functions come with two extra reserved slots on them. Use the 0-th slot
|
3116
|
+
// to communicate the wrapped function to our forwarder.
|
3117
|
+
return JS_SetReservedSlot(cx, newfunobj, 0, argv[0]);
|
3118
|
+
}
|
3119
|
+
|
3120
|
+
static JSBool
|
3121
|
+
sandbox_enumerate(JSContext *cx, JSObject *obj)
|
3122
|
+
{
|
3123
|
+
return JS_EnumerateStandardClasses(cx, obj);
|
3124
|
+
}
|
3125
|
+
|
3126
|
+
static JSBool
|
3127
|
+
sandbox_resolve(JSContext *cx, JSObject *obj, jsval id)
|
3128
|
+
{
|
3129
|
+
JSBool resolved;
|
3130
|
+
return JS_ResolveStandardClass(cx, obj, id, &resolved);
|
3131
|
+
}
|
3132
|
+
|
3133
|
+
static void
|
3134
|
+
sandbox_finalize(JSContext *cx, JSObject *obj)
|
3135
|
+
{
|
3136
|
+
nsIScriptObjectPrincipal *sop =
|
3137
|
+
(nsIScriptObjectPrincipal *)xpc_GetJSPrivate(obj);
|
3138
|
+
NS_IF_RELEASE(sop);
|
3139
|
+
}
|
3140
|
+
|
3141
|
+
static JSBool
|
3142
|
+
sandbox_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
3143
|
+
{
|
3144
|
+
if (type == JSTYPE_OBJECT) {
|
3145
|
+
*vp = OBJECT_TO_JSVAL(obj);
|
3146
|
+
return JS_TRUE;
|
3147
|
+
}
|
3148
|
+
|
3149
|
+
return JS_ConvertStub(cx, obj, type, vp);
|
3150
|
+
}
|
3151
|
+
|
3152
|
+
static JSClass SandboxClass = {
|
3153
|
+
"Sandbox",
|
3154
|
+
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_GLOBAL_FLAGS,
|
3155
|
+
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
3156
|
+
sandbox_enumerate, sandbox_resolve, sandbox_convert, sandbox_finalize,
|
3157
|
+
JSCLASS_NO_OPTIONAL_MEMBERS
|
3158
|
+
};
|
3159
|
+
|
3160
|
+
static JSFunctionSpec SandboxFunctions[] = {
|
3161
|
+
{"dump", SandboxDump, 1,0,0},
|
3162
|
+
{"debug", SandboxDebug, 1,0,0},
|
3163
|
+
{"importFunction", SandboxImport, 1,0,0},
|
3164
|
+
{nsnull,nsnull,0,0,0}
|
3165
|
+
};
|
3166
|
+
|
3167
|
+
#endif /* !XPCONNECT_STANDALONE */
|
3168
|
+
|
3169
|
+
/***************************************************************************/
|
3170
|
+
nsXPCComponents_utils_Sandbox::nsXPCComponents_utils_Sandbox()
|
3171
|
+
{
|
3172
|
+
}
|
3173
|
+
|
3174
|
+
nsXPCComponents_utils_Sandbox::~nsXPCComponents_utils_Sandbox()
|
3175
|
+
{
|
3176
|
+
}
|
3177
|
+
|
3178
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_utils_Sandbox)
|
3179
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_utils_Sandbox)
|
3180
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
3181
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_utils_Sandbox)
|
3182
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
3183
|
+
|
3184
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_utils_Sandbox)
|
3185
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents_utils_Sandbox)
|
3186
|
+
|
3187
|
+
// We use the nsIXPScriptable macros to generate lots of stuff for us.
|
3188
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents_utils_Sandbox
|
3189
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents_utils_Sandbox"
|
3190
|
+
#define XPC_MAP_WANT_CALL
|
3191
|
+
#define XPC_MAP_WANT_CONSTRUCT
|
3192
|
+
#define XPC_MAP_FLAGS 0
|
3193
|
+
#include "xpc_map_end.h" /* This #undef's the above. */
|
3194
|
+
|
3195
|
+
#ifndef XPCONNECT_STANDALONE
|
3196
|
+
nsresult
|
3197
|
+
xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop)
|
3198
|
+
{
|
3199
|
+
// Create the sandbox global object
|
3200
|
+
nsresult rv;
|
3201
|
+
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
|
3202
|
+
if(NS_FAILED(rv))
|
3203
|
+
return NS_ERROR_XPC_UNEXPECTED;
|
3204
|
+
|
3205
|
+
XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
|
3206
|
+
if (!tempcx)
|
3207
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3208
|
+
|
3209
|
+
AutoJSRequestWithNoCallContext req(tempcx);
|
3210
|
+
JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
|
3211
|
+
if (!sandbox)
|
3212
|
+
return NS_ERROR_XPC_UNEXPECTED;
|
3213
|
+
|
3214
|
+
JS_SetGlobalObject(tempcx, sandbox);
|
3215
|
+
|
3216
|
+
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(prinOrSop));
|
3217
|
+
|
3218
|
+
if (!sop) {
|
3219
|
+
nsCOMPtr<nsIPrincipal> principal(do_QueryInterface(prinOrSop));
|
3220
|
+
|
3221
|
+
if (!principal) {
|
3222
|
+
principal = do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
|
3223
|
+
NS_ASSERTION(NS_FAILED(rv) || principal,
|
3224
|
+
"Bad return from do_CreateInstance");
|
3225
|
+
|
3226
|
+
if (!principal || NS_FAILED(rv)) {
|
3227
|
+
if (NS_SUCCEEDED(rv))
|
3228
|
+
rv = NS_ERROR_FAILURE;
|
3229
|
+
|
3230
|
+
return rv;
|
3231
|
+
}
|
3232
|
+
}
|
3233
|
+
|
3234
|
+
sop = new PrincipalHolder(principal);
|
3235
|
+
if (!sop)
|
3236
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3237
|
+
}
|
3238
|
+
|
3239
|
+
// Pass on ownership of sop to |sandbox|.
|
3240
|
+
|
3241
|
+
{
|
3242
|
+
nsIScriptObjectPrincipal *tmp = sop;
|
3243
|
+
|
3244
|
+
if (!JS_SetPrivate(cx, sandbox, tmp)) {
|
3245
|
+
return NS_ERROR_XPC_UNEXPECTED;
|
3246
|
+
}
|
3247
|
+
|
3248
|
+
NS_ADDREF(tmp);
|
3249
|
+
}
|
3250
|
+
|
3251
|
+
rv = xpc->InitClasses(cx, sandbox);
|
3252
|
+
if (NS_SUCCEEDED(rv) &&
|
3253
|
+
!JS_DefineFunctions(cx, sandbox, SandboxFunctions)) {
|
3254
|
+
rv = NS_ERROR_FAILURE;
|
3255
|
+
}
|
3256
|
+
if (NS_FAILED(rv))
|
3257
|
+
return NS_ERROR_XPC_UNEXPECTED;
|
3258
|
+
|
3259
|
+
if (vp)
|
3260
|
+
*vp = OBJECT_TO_JSVAL(sandbox);
|
3261
|
+
|
3262
|
+
return NS_OK;
|
3263
|
+
}
|
3264
|
+
#endif /* !XPCONNECT_STANDALONE */
|
3265
|
+
|
3266
|
+
/* PRBool call(in nsIXPConnectWrappedNative wrapper,
|
3267
|
+
in JSContextPtr cx,
|
3268
|
+
in JSObjectPtr obj,
|
3269
|
+
in PRUint32 argc,
|
3270
|
+
in JSValPtr argv,
|
3271
|
+
in JSValPtr vp);
|
3272
|
+
*/
|
3273
|
+
NS_IMETHODIMP
|
3274
|
+
nsXPCComponents_utils_Sandbox::Call(nsIXPConnectWrappedNative *wrapper,
|
3275
|
+
JSContext * cx,
|
3276
|
+
JSObject * obj,
|
3277
|
+
PRUint32 argc,
|
3278
|
+
jsval * argv,
|
3279
|
+
jsval * vp,
|
3280
|
+
PRBool *_retval)
|
3281
|
+
{
|
3282
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
3283
|
+
}
|
3284
|
+
|
3285
|
+
/* PRBool construct(in nsIXPConnectWrappedNative wrapper,
|
3286
|
+
in JSContextPtr cx,
|
3287
|
+
in JSObjectPtr obj,
|
3288
|
+
in PRUint32 argc,
|
3289
|
+
in JSValPtr argv,
|
3290
|
+
in JSValPtr vp);
|
3291
|
+
*/
|
3292
|
+
NS_IMETHODIMP
|
3293
|
+
nsXPCComponents_utils_Sandbox::Construct(nsIXPConnectWrappedNative *wrapper,
|
3294
|
+
JSContext * cx,
|
3295
|
+
JSObject * obj,
|
3296
|
+
PRUint32 argc,
|
3297
|
+
jsval * argv,
|
3298
|
+
jsval * vp,
|
3299
|
+
PRBool *_retval)
|
3300
|
+
{
|
3301
|
+
return CallOrConstruct(wrapper, cx, obj, argc, argv, vp, _retval);
|
3302
|
+
}
|
3303
|
+
|
3304
|
+
NS_IMETHODIMP
|
3305
|
+
nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
3306
|
+
JSContext * cx, JSObject * obj,
|
3307
|
+
PRUint32 argc, jsval * argv,
|
3308
|
+
jsval * vp, PRBool *_retval)
|
3309
|
+
{
|
3310
|
+
#ifdef XPCONNECT_STANDALONE
|
3311
|
+
return NS_ERROR_NOT_AVAILABLE;
|
3312
|
+
#else /* XPCONNECT_STANDALONE */
|
3313
|
+
if (argc < 1)
|
3314
|
+
return ThrowAndFail(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx, _retval);
|
3315
|
+
|
3316
|
+
nsresult rv;
|
3317
|
+
|
3318
|
+
// Make sure to set up principals on the sandbox before initing classes
|
3319
|
+
nsCOMPtr<nsIScriptObjectPrincipal> sop;
|
3320
|
+
nsCOMPtr<nsIPrincipal> principal;
|
3321
|
+
nsISupports *prinOrSop = nsnull;
|
3322
|
+
if (JSVAL_IS_STRING(argv[0])) {
|
3323
|
+
JSString *codebasestr = JSVAL_TO_STRING(argv[0]);
|
3324
|
+
nsAutoString codebase(reinterpret_cast<PRUnichar*>
|
3325
|
+
(JS_GetStringChars(codebasestr)),
|
3326
|
+
JS_GetStringLength(codebasestr));
|
3327
|
+
nsCOMPtr<nsIURI> uri;
|
3328
|
+
rv = NS_NewURI(getter_AddRefs(uri), codebase);
|
3329
|
+
if (NS_FAILED(rv)) {
|
3330
|
+
return ThrowAndFail(rv, cx, _retval);
|
3331
|
+
}
|
3332
|
+
|
3333
|
+
nsCOMPtr<nsIScriptSecurityManager> secman =
|
3334
|
+
do_GetService(kScriptSecurityManagerContractID);
|
3335
|
+
if (!secman ||
|
3336
|
+
NS_FAILED(rv = secman->GetCodebasePrincipal(uri,
|
3337
|
+
getter_AddRefs(principal))) ||
|
3338
|
+
!principal) {
|
3339
|
+
if (NS_SUCCEEDED(rv))
|
3340
|
+
rv = NS_ERROR_FAILURE;
|
3341
|
+
return ThrowAndFail(rv, cx, _retval);
|
3342
|
+
}
|
3343
|
+
|
3344
|
+
prinOrSop = principal;
|
3345
|
+
} else {
|
3346
|
+
if (!JSVAL_IS_PRIMITIVE(argv[0])) {
|
3347
|
+
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
|
3348
|
+
if(!xpc)
|
3349
|
+
return NS_ERROR_XPC_UNEXPECTED;
|
3350
|
+
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
3351
|
+
xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(argv[0]),
|
3352
|
+
getter_AddRefs(wrapper));
|
3353
|
+
|
3354
|
+
if (wrapper) {
|
3355
|
+
sop = do_QueryWrappedNative(wrapper);
|
3356
|
+
if (sop) {
|
3357
|
+
prinOrSop = sop;
|
3358
|
+
} else {
|
3359
|
+
principal = do_QueryWrappedNative(wrapper);
|
3360
|
+
prinOrSop = principal;
|
3361
|
+
}
|
3362
|
+
}
|
3363
|
+
}
|
3364
|
+
|
3365
|
+
if (!prinOrSop)
|
3366
|
+
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
|
3367
|
+
}
|
3368
|
+
|
3369
|
+
rv = xpc_CreateSandboxObject(cx, vp, prinOrSop);
|
3370
|
+
|
3371
|
+
if (NS_FAILED(rv)) {
|
3372
|
+
return ThrowAndFail(rv, cx, _retval);
|
3373
|
+
}
|
3374
|
+
|
3375
|
+
*_retval = PR_TRUE;
|
3376
|
+
|
3377
|
+
return rv;
|
3378
|
+
#endif /* XPCONNECT_STANDALONE */
|
3379
|
+
}
|
3380
|
+
|
3381
|
+
class ContextHolder : public nsISupports
|
3382
|
+
{
|
3383
|
+
public:
|
3384
|
+
ContextHolder(JSContext *aOuterCx, JSObject *aSandbox);
|
3385
|
+
|
3386
|
+
JSContext * GetJSContext()
|
3387
|
+
{
|
3388
|
+
return mJSContext;
|
3389
|
+
}
|
3390
|
+
|
3391
|
+
NS_DECL_ISUPPORTS
|
3392
|
+
|
3393
|
+
private:
|
3394
|
+
static JSBool ContextHolderOperationCallback(JSContext *cx);
|
3395
|
+
|
3396
|
+
XPCAutoJSContext mJSContext;
|
3397
|
+
JSContext* mOrigCx;
|
3398
|
+
};
|
3399
|
+
|
3400
|
+
NS_IMPL_ISUPPORTS0(ContextHolder)
|
3401
|
+
|
3402
|
+
ContextHolder::ContextHolder(JSContext *aOuterCx, JSObject *aSandbox)
|
3403
|
+
: mJSContext(JS_NewContext(JS_GetRuntime(aOuterCx), 1024), JS_FALSE),
|
3404
|
+
mOrigCx(aOuterCx)
|
3405
|
+
{
|
3406
|
+
if(mJSContext)
|
3407
|
+
{
|
3408
|
+
JS_SetOptions(mJSContext,
|
3409
|
+
JSOPTION_DONT_REPORT_UNCAUGHT |
|
3410
|
+
JSOPTION_PRIVATE_IS_NSISUPPORTS);
|
3411
|
+
JS_SetGlobalObject(mJSContext, aSandbox);
|
3412
|
+
JS_SetContextPrivate(mJSContext, this);
|
3413
|
+
JS_SetOperationCallback(mJSContext, ContextHolderOperationCallback);
|
3414
|
+
}
|
3415
|
+
}
|
3416
|
+
|
3417
|
+
JSBool
|
3418
|
+
ContextHolder::ContextHolderOperationCallback(JSContext *cx)
|
3419
|
+
{
|
3420
|
+
ContextHolder* thisObject =
|
3421
|
+
static_cast<ContextHolder*>(JS_GetContextPrivate(cx));
|
3422
|
+
NS_ASSERTION(thisObject, "How did that happen?");
|
3423
|
+
|
3424
|
+
JSContext *origCx = thisObject->mOrigCx;
|
3425
|
+
JSOperationCallback callback = JS_GetOperationCallback(origCx);
|
3426
|
+
JSBool ok = JS_TRUE;
|
3427
|
+
if(callback)
|
3428
|
+
ok = callback(origCx);
|
3429
|
+
return ok;
|
3430
|
+
}
|
3431
|
+
|
3432
|
+
/***************************************************************************/
|
3433
|
+
|
3434
|
+
/* void evalInSandbox(in AString source, in nativeobj sandbox); */
|
3435
|
+
NS_IMETHODIMP
|
3436
|
+
nsXPCComponents_Utils::EvalInSandbox(const nsAString &source)
|
3437
|
+
{
|
3438
|
+
#ifdef XPCONNECT_STANDALONE
|
3439
|
+
return NS_ERROR_NOT_AVAILABLE;
|
3440
|
+
#else /* XPCONNECT_STANDALONE */
|
3441
|
+
nsresult rv;
|
3442
|
+
|
3443
|
+
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
|
3444
|
+
if(NS_FAILED(rv))
|
3445
|
+
return rv;
|
3446
|
+
|
3447
|
+
// get the xpconnect native call context
|
3448
|
+
nsAXPCNativeCallContext *cc = nsnull;
|
3449
|
+
xpc->GetCurrentNativeCallContext(&cc);
|
3450
|
+
if(!cc)
|
3451
|
+
return NS_ERROR_FAILURE;
|
3452
|
+
|
3453
|
+
// Get JSContext of current call
|
3454
|
+
JSContext* cx;
|
3455
|
+
rv = cc->GetJSContext(&cx);
|
3456
|
+
if(NS_FAILED(rv) || !cx)
|
3457
|
+
return NS_ERROR_FAILURE;
|
3458
|
+
|
3459
|
+
// get place for return value
|
3460
|
+
jsval *rval = nsnull;
|
3461
|
+
rv = cc->GetRetValPtr(&rval);
|
3462
|
+
if(NS_FAILED(rv) || !rval)
|
3463
|
+
return NS_ERROR_FAILURE;
|
3464
|
+
|
3465
|
+
// get argc and argv and verify arg count
|
3466
|
+
PRUint32 argc;
|
3467
|
+
rv = cc->GetArgc(&argc);
|
3468
|
+
if(NS_FAILED(rv))
|
3469
|
+
return rv;
|
3470
|
+
|
3471
|
+
// The second argument is the sandbox object. It is required.
|
3472
|
+
if (argc < 2)
|
3473
|
+
return NS_ERROR_XPC_NOT_ENOUGH_ARGS;
|
3474
|
+
|
3475
|
+
jsval *argv;
|
3476
|
+
rv = cc->GetArgvPtr(&argv);
|
3477
|
+
if (NS_FAILED(rv))
|
3478
|
+
return rv;
|
3479
|
+
|
3480
|
+
JSObject *sandbox;
|
3481
|
+
char *jsVersionStr = NULL;
|
3482
|
+
char *filenameStr = NULL;
|
3483
|
+
PRInt32 lineNo = 0;
|
3484
|
+
|
3485
|
+
JSBool ok = JS_ConvertArguments(cx, argc, argv, "*o/ssi",
|
3486
|
+
&sandbox, &jsVersionStr,
|
3487
|
+
&filenameStr, &lineNo);
|
3488
|
+
|
3489
|
+
if (!ok)
|
3490
|
+
return NS_ERROR_INVALID_ARG;
|
3491
|
+
|
3492
|
+
JSVersion jsVersion = JSVERSION_DEFAULT;
|
3493
|
+
|
3494
|
+
// Optional third argument: JS version, as a string.
|
3495
|
+
if (jsVersionStr) {
|
3496
|
+
jsVersion = JS_StringToVersion(jsVersionStr);
|
3497
|
+
if (jsVersion == JSVERSION_UNKNOWN)
|
3498
|
+
return NS_ERROR_INVALID_ARG;
|
3499
|
+
}
|
3500
|
+
|
3501
|
+
nsXPIDLCString filename;
|
3502
|
+
|
3503
|
+
// Optional fourth and fifth arguments: filename and line number.
|
3504
|
+
if (filenameStr) {
|
3505
|
+
filename = filenameStr;
|
3506
|
+
} else {
|
3507
|
+
// Get the current source info from xpc.
|
3508
|
+
nsCOMPtr<nsIStackFrame> frame;
|
3509
|
+
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
3510
|
+
if (frame) {
|
3511
|
+
frame->GetFilename(getter_Copies(filename));
|
3512
|
+
frame->GetLineNumber(&lineNo);
|
3513
|
+
}
|
3514
|
+
}
|
3515
|
+
|
3516
|
+
rv = xpc_EvalInSandbox(cx, sandbox, source, filename.get(), lineNo,
|
3517
|
+
jsVersion, PR_FALSE, rval);
|
3518
|
+
|
3519
|
+
if (NS_SUCCEEDED(rv) && !JS_IsExceptionPending(cx))
|
3520
|
+
cc->SetReturnValueWasSet(PR_TRUE);
|
3521
|
+
|
3522
|
+
return rv;
|
3523
|
+
#endif /* XPCONNECT_STANDALONE */
|
3524
|
+
}
|
3525
|
+
|
3526
|
+
#ifndef XPCONNECT_STANDALONE
|
3527
|
+
nsresult
|
3528
|
+
xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
3529
|
+
const char *filename, PRInt32 lineNo,
|
3530
|
+
JSVersion jsVersion, PRBool returnStringOnly, jsval *rval)
|
3531
|
+
{
|
3532
|
+
if (STOBJ_GET_CLASS(sandbox) != &SandboxClass)
|
3533
|
+
return NS_ERROR_INVALID_ARG;
|
3534
|
+
|
3535
|
+
nsIScriptObjectPrincipal *sop =
|
3536
|
+
(nsIScriptObjectPrincipal*)xpc_GetJSPrivate(sandbox);
|
3537
|
+
NS_ASSERTION(sop, "Invalid sandbox passed");
|
3538
|
+
nsCOMPtr<nsIPrincipal> prin = sop->GetPrincipal();
|
3539
|
+
|
3540
|
+
JSPrincipals *jsPrincipals;
|
3541
|
+
|
3542
|
+
if (!prin ||
|
3543
|
+
NS_FAILED(prin->GetJSPrincipals(cx, &jsPrincipals)) ||
|
3544
|
+
!jsPrincipals) {
|
3545
|
+
return NS_ERROR_FAILURE;
|
3546
|
+
}
|
3547
|
+
|
3548
|
+
nsRefPtr<ContextHolder> sandcx = new ContextHolder(cx, sandbox);
|
3549
|
+
if(!sandcx || !sandcx->GetJSContext()) {
|
3550
|
+
JS_ReportError(cx, "Can't prepare context for evalInSandbox");
|
3551
|
+
JSPRINCIPALS_DROP(cx, jsPrincipals);
|
3552
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3553
|
+
}
|
3554
|
+
|
3555
|
+
if (jsVersion != JSVERSION_DEFAULT)
|
3556
|
+
JS_SetVersion(sandcx->GetJSContext(), jsVersion);
|
3557
|
+
|
3558
|
+
XPCPerThreadData *data = XPCPerThreadData::GetData(cx);
|
3559
|
+
XPCJSContextStack *stack = nsnull;
|
3560
|
+
if (data && (stack = data->GetJSContextStack())) {
|
3561
|
+
if (NS_FAILED(stack->Push(sandcx->GetJSContext()))) {
|
3562
|
+
JS_ReportError(cx,
|
3563
|
+
"Unable to initialize XPConnect with the sandbox context");
|
3564
|
+
JSPRINCIPALS_DROP(cx, jsPrincipals);
|
3565
|
+
return NS_ERROR_FAILURE;
|
3566
|
+
}
|
3567
|
+
}
|
3568
|
+
|
3569
|
+
if (!filename) {
|
3570
|
+
// Default the filename to the codebase.
|
3571
|
+
filename = jsPrincipals->codebase;
|
3572
|
+
lineNo = 1;
|
3573
|
+
}
|
3574
|
+
|
3575
|
+
nsresult rv = NS_OK;
|
3576
|
+
|
3577
|
+
{
|
3578
|
+
AutoJSRequestWithNoCallContext req(sandcx->GetJSContext());
|
3579
|
+
JSString *str = nsnull;
|
3580
|
+
if (!JS_EvaluateUCScriptForPrincipals(sandcx->GetJSContext(), sandbox,
|
3581
|
+
jsPrincipals,
|
3582
|
+
reinterpret_cast<const jschar *>
|
3583
|
+
(PromiseFlatString(source).get()),
|
3584
|
+
source.Length(), filename, lineNo,
|
3585
|
+
rval) ||
|
3586
|
+
(returnStringOnly &&
|
3587
|
+
!JSVAL_IS_VOID(*rval) &&
|
3588
|
+
!(str = JS_ValueToString(sandcx->GetJSContext(), *rval)))) {
|
3589
|
+
jsval exn;
|
3590
|
+
if (JS_GetPendingException(sandcx->GetJSContext(), &exn)) {
|
3591
|
+
// Stash the exception in |cx| so we can execute code on
|
3592
|
+
// sandcx without a pending exception.
|
3593
|
+
{
|
3594
|
+
AutoJSSuspendRequestWithNoCallContext sus(sandcx->GetJSContext());
|
3595
|
+
AutoJSRequestWithNoCallContext cxreq(cx);
|
3596
|
+
|
3597
|
+
JS_SetPendingException(cx, exn);
|
3598
|
+
}
|
3599
|
+
|
3600
|
+
JS_ClearPendingException(sandcx->GetJSContext());
|
3601
|
+
if (returnStringOnly) {
|
3602
|
+
// The caller asked for strings only, convert the
|
3603
|
+
// exception into a string.
|
3604
|
+
str = JS_ValueToString(sandcx->GetJSContext(), exn);
|
3605
|
+
|
3606
|
+
AutoJSSuspendRequestWithNoCallContext sus(sandcx->GetJSContext());
|
3607
|
+
AutoJSRequestWithNoCallContext cxreq(cx);
|
3608
|
+
if (str) {
|
3609
|
+
// We converted the exception to a string. Use that
|
3610
|
+
// as the value exception.
|
3611
|
+
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
|
3612
|
+
} else {
|
3613
|
+
JS_ClearPendingException(cx);
|
3614
|
+
rv = NS_ERROR_FAILURE;
|
3615
|
+
}
|
3616
|
+
}
|
3617
|
+
|
3618
|
+
// Clear str so we don't confuse callers.
|
3619
|
+
str = nsnull;
|
3620
|
+
} else {
|
3621
|
+
rv = NS_ERROR_OUT_OF_MEMORY;
|
3622
|
+
}
|
3623
|
+
}
|
3624
|
+
|
3625
|
+
if (str) {
|
3626
|
+
*rval = STRING_TO_JSVAL(str);
|
3627
|
+
}
|
3628
|
+
}
|
3629
|
+
|
3630
|
+
if (stack) {
|
3631
|
+
stack->Pop(nsnull);
|
3632
|
+
}
|
3633
|
+
|
3634
|
+
JSPRINCIPALS_DROP(cx, jsPrincipals);
|
3635
|
+
|
3636
|
+
return rv;
|
3637
|
+
}
|
3638
|
+
#endif /* !XPCONNECT_STANDALONE */
|
3639
|
+
|
3640
|
+
/* JSObject import (in AUTF8String registryLocation,
|
3641
|
+
* [optional] in JSObject targetObj);
|
3642
|
+
*/
|
3643
|
+
NS_IMETHODIMP
|
3644
|
+
nsXPCComponents_Utils::Import(const nsACString & registryLocation)
|
3645
|
+
{
|
3646
|
+
#ifdef MOZ_JSLOADER
|
3647
|
+
nsCOMPtr<xpcIJSModuleLoader> moduleloader =
|
3648
|
+
do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
|
3649
|
+
if (!moduleloader)
|
3650
|
+
return NS_ERROR_FAILURE;
|
3651
|
+
return moduleloader->Import(registryLocation);
|
3652
|
+
#else
|
3653
|
+
return NS_ERROR_NOT_AVAILABLE;
|
3654
|
+
#endif
|
3655
|
+
}
|
3656
|
+
|
3657
|
+
/* xpcIJSWeakReference getWeakReference (); */
|
3658
|
+
NS_IMETHODIMP
|
3659
|
+
nsXPCComponents_Utils::GetWeakReference(xpcIJSWeakReference **_retval)
|
3660
|
+
{
|
3661
|
+
nsRefPtr<xpcJSWeakReference> ref(new xpcJSWeakReference());
|
3662
|
+
if (!ref)
|
3663
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3664
|
+
ref->Init();
|
3665
|
+
*_retval = ref;
|
3666
|
+
NS_ADDREF(*_retval);
|
3667
|
+
return NS_OK;
|
3668
|
+
}
|
3669
|
+
|
3670
|
+
/* void forceGC (); */
|
3671
|
+
NS_IMETHODIMP
|
3672
|
+
nsXPCComponents_Utils::ForceGC()
|
3673
|
+
{
|
3674
|
+
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
3675
|
+
if (!xpc)
|
3676
|
+
return NS_ERROR_FAILURE;
|
3677
|
+
|
3678
|
+
// get the xpconnect native call context
|
3679
|
+
nsAXPCNativeCallContext *cc = nsnull;
|
3680
|
+
nsresult rv = xpc->GetCurrentNativeCallContext(&cc);
|
3681
|
+
if (!cc)
|
3682
|
+
return rv;
|
3683
|
+
|
3684
|
+
// Get JSContext of current call
|
3685
|
+
JSContext* cx;
|
3686
|
+
cc->GetJSContext(&cx);
|
3687
|
+
if (!cx)
|
3688
|
+
return NS_ERROR_FAILURE;
|
3689
|
+
|
3690
|
+
JS_GC(cx);
|
3691
|
+
|
3692
|
+
return NS_OK;
|
3693
|
+
}
|
3694
|
+
|
3695
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
3696
|
+
/* string canCreateWrapper (in nsIIDPtr iid); */
|
3697
|
+
NS_IMETHODIMP
|
3698
|
+
nsXPCComponents_Utils::CanCreateWrapper(const nsIID * iid, char **_retval)
|
3699
|
+
{
|
3700
|
+
// We let anyone do this...
|
3701
|
+
*_retval = xpc_CloneAllAccess();
|
3702
|
+
return NS_OK;
|
3703
|
+
}
|
3704
|
+
|
3705
|
+
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
3706
|
+
NS_IMETHODIMP
|
3707
|
+
nsXPCComponents_Utils::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
3708
|
+
{
|
3709
|
+
static const char* allowed[] = { "lookupMethod", "evalInSandbox", nsnull };
|
3710
|
+
*_retval = xpc_CheckAccessList(methodName, allowed);
|
3711
|
+
return NS_OK;
|
3712
|
+
}
|
3713
|
+
|
3714
|
+
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
3715
|
+
NS_IMETHODIMP
|
3716
|
+
nsXPCComponents_Utils::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
3717
|
+
{
|
3718
|
+
*_retval = nsnull;
|
3719
|
+
return NS_OK;
|
3720
|
+
}
|
3721
|
+
|
3722
|
+
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
3723
|
+
NS_IMETHODIMP
|
3724
|
+
nsXPCComponents_Utils::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
3725
|
+
{
|
3726
|
+
// If you have to ask, then the answer is NO
|
3727
|
+
*_retval = nsnull;
|
3728
|
+
return NS_OK;
|
3729
|
+
}
|
3730
|
+
#endif
|
3731
|
+
|
3732
|
+
/***************************************************************************/
|
3733
|
+
/***************************************************************************/
|
3734
|
+
/***************************************************************************/
|
3735
|
+
|
3736
|
+
// XXXjband We ought to cache the wrapper in the object's slots rather than
|
3737
|
+
// re-wrapping on demand
|
3738
|
+
|
3739
|
+
NS_INTERFACE_MAP_BEGIN(nsXPCComponents)
|
3740
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents)
|
3741
|
+
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
3742
|
+
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
3743
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
3744
|
+
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
|
3745
|
+
#endif
|
3746
|
+
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents)
|
3747
|
+
NS_INTERFACE_MAP_END_THREADSAFE
|
3748
|
+
|
3749
|
+
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents)
|
3750
|
+
NS_IMPL_THREADSAFE_RELEASE(nsXPCComponents)
|
3751
|
+
|
3752
|
+
/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval]
|
3753
|
+
out nsIIDPtr array); */
|
3754
|
+
NS_IMETHODIMP
|
3755
|
+
nsXPCComponents::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
|
3756
|
+
{
|
3757
|
+
PRUint32 count = 2;
|
3758
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
3759
|
+
++count;
|
3760
|
+
#endif
|
3761
|
+
*aCount = count;
|
3762
|
+
nsIID **array;
|
3763
|
+
*aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*)));
|
3764
|
+
if(!array)
|
3765
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3766
|
+
|
3767
|
+
PRUint32 index = 0;
|
3768
|
+
nsIID* clone;
|
3769
|
+
#define PUSH_IID(id) \
|
3770
|
+
clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \
|
3771
|
+
sizeof(nsIID))); \
|
3772
|
+
if (!clone) \
|
3773
|
+
goto oom; \
|
3774
|
+
array[index++] = clone;
|
3775
|
+
|
3776
|
+
PUSH_IID(nsIXPCComponents)
|
3777
|
+
PUSH_IID(nsIXPCScriptable)
|
3778
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
3779
|
+
PUSH_IID(nsISecurityCheckedComponent)
|
3780
|
+
#endif
|
3781
|
+
#undef PUSH_IID
|
3782
|
+
|
3783
|
+
return NS_OK;
|
3784
|
+
oom:
|
3785
|
+
while (index)
|
3786
|
+
nsMemory::Free(array[--index]);
|
3787
|
+
nsMemory::Free(array);
|
3788
|
+
*aArray = nsnull;
|
3789
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
3790
|
+
}
|
3791
|
+
|
3792
|
+
/* nsISupports getHelperForLanguage (in PRUint32 language); */
|
3793
|
+
NS_IMETHODIMP
|
3794
|
+
nsXPCComponents::GetHelperForLanguage(PRUint32 language,
|
3795
|
+
nsISupports **retval)
|
3796
|
+
{
|
3797
|
+
*retval = nsnull;
|
3798
|
+
return NS_OK;
|
3799
|
+
}
|
3800
|
+
|
3801
|
+
/* readonly attribute string contractID; */
|
3802
|
+
NS_IMETHODIMP
|
3803
|
+
nsXPCComponents::GetContractID(char * *aContractID)
|
3804
|
+
{
|
3805
|
+
*aContractID = nsnull;
|
3806
|
+
return NS_ERROR_NOT_AVAILABLE;
|
3807
|
+
}
|
3808
|
+
|
3809
|
+
/* readonly attribute string classDescription; */
|
3810
|
+
NS_IMETHODIMP
|
3811
|
+
nsXPCComponents::GetClassDescription(char * *aClassDescription)
|
3812
|
+
{
|
3813
|
+
static const char classDescription[] = "XPCComponents";
|
3814
|
+
*aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription));
|
3815
|
+
return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
3816
|
+
}
|
3817
|
+
|
3818
|
+
/* readonly attribute nsCIDPtr classID; */
|
3819
|
+
NS_IMETHODIMP
|
3820
|
+
nsXPCComponents::GetClassID(nsCID * *aClassID)
|
3821
|
+
{
|
3822
|
+
*aClassID = nsnull;
|
3823
|
+
return NS_OK;
|
3824
|
+
}
|
3825
|
+
|
3826
|
+
/* readonly attribute PRUint32 implementationLanguage; */
|
3827
|
+
NS_IMETHODIMP
|
3828
|
+
nsXPCComponents::GetImplementationLanguage(
|
3829
|
+
PRUint32 *aImplementationLanguage)
|
3830
|
+
{
|
3831
|
+
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
3832
|
+
return NS_OK;
|
3833
|
+
}
|
3834
|
+
|
3835
|
+
/* readonly attribute PRUint32 flags; */
|
3836
|
+
NS_IMETHODIMP
|
3837
|
+
nsXPCComponents::GetFlags(PRUint32 *aFlags)
|
3838
|
+
{
|
3839
|
+
*aFlags = nsIClassInfo::THREADSAFE;
|
3840
|
+
return NS_OK;
|
3841
|
+
}
|
3842
|
+
|
3843
|
+
/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */
|
3844
|
+
NS_IMETHODIMP
|
3845
|
+
nsXPCComponents::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
3846
|
+
{
|
3847
|
+
return NS_ERROR_NOT_AVAILABLE;
|
3848
|
+
}
|
3849
|
+
|
3850
|
+
nsXPCComponents::nsXPCComponents()
|
3851
|
+
: mInterfaces(nsnull),
|
3852
|
+
mInterfacesByID(nsnull),
|
3853
|
+
mClasses(nsnull),
|
3854
|
+
mClassesByID(nsnull),
|
3855
|
+
mResults(nsnull),
|
3856
|
+
mID(nsnull),
|
3857
|
+
mException(nsnull),
|
3858
|
+
mConstructor(nsnull),
|
3859
|
+
mUtils(nsnull)
|
3860
|
+
{
|
3861
|
+
}
|
3862
|
+
|
3863
|
+
nsXPCComponents::~nsXPCComponents()
|
3864
|
+
{
|
3865
|
+
ClearMembers();
|
3866
|
+
}
|
3867
|
+
|
3868
|
+
void
|
3869
|
+
nsXPCComponents::ClearMembers()
|
3870
|
+
{
|
3871
|
+
NS_IF_RELEASE(mInterfaces);
|
3872
|
+
NS_IF_RELEASE(mInterfacesByID);
|
3873
|
+
NS_IF_RELEASE(mClasses);
|
3874
|
+
NS_IF_RELEASE(mClassesByID);
|
3875
|
+
NS_IF_RELEASE(mResults);
|
3876
|
+
NS_IF_RELEASE(mID);
|
3877
|
+
NS_IF_RELEASE(mException);
|
3878
|
+
NS_IF_RELEASE(mConstructor);
|
3879
|
+
NS_IF_RELEASE(mUtils);
|
3880
|
+
}
|
3881
|
+
|
3882
|
+
/*******************************************/
|
3883
|
+
#define XPC_IMPL_GET_OBJ_METHOD(_b, _n) \
|
3884
|
+
NS_IMETHODIMP nsXPCComponents::Get##_n(_b##_n * *a##_n) { \
|
3885
|
+
NS_ENSURE_ARG_POINTER(a##_n); \
|
3886
|
+
if(!m##_n) { \
|
3887
|
+
if(!(m##_n = new nsXPCComponents_##_n())) { \
|
3888
|
+
*a##_n = nsnull; \
|
3889
|
+
return NS_ERROR_OUT_OF_MEMORY; \
|
3890
|
+
} \
|
3891
|
+
NS_ADDREF(m##_n); \
|
3892
|
+
} \
|
3893
|
+
NS_ADDREF(m##_n); \
|
3894
|
+
*a##_n = m##_n; \
|
3895
|
+
return NS_OK; \
|
3896
|
+
}
|
3897
|
+
|
3898
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIScriptable, Interfaces)
|
3899
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIScriptable, InterfacesByID)
|
3900
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Classes)
|
3901
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, ClassesByID)
|
3902
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Results)
|
3903
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, ID)
|
3904
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Exception)
|
3905
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Constructor)
|
3906
|
+
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Utils)
|
3907
|
+
|
3908
|
+
#undef XPC_IMPL_GET_OBJ_METHOD
|
3909
|
+
/*******************************************/
|
3910
|
+
|
3911
|
+
NS_IMETHODIMP
|
3912
|
+
nsXPCComponents::IsSuccessCode(nsresult result, PRBool *out)
|
3913
|
+
{
|
3914
|
+
*out = NS_SUCCEEDED(result);
|
3915
|
+
return NS_OK;
|
3916
|
+
}
|
3917
|
+
|
3918
|
+
NS_IMETHODIMP
|
3919
|
+
nsXPCComponents::GetStack(nsIStackFrame * *aStack)
|
3920
|
+
{
|
3921
|
+
nsresult rv;
|
3922
|
+
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
3923
|
+
if(!xpc)
|
3924
|
+
return NS_ERROR_FAILURE;
|
3925
|
+
rv = xpc->GetCurrentJSStack(aStack);
|
3926
|
+
return rv;
|
3927
|
+
}
|
3928
|
+
|
3929
|
+
NS_IMETHODIMP
|
3930
|
+
nsXPCComponents::GetManager(nsIComponentManager * *aManager)
|
3931
|
+
{
|
3932
|
+
NS_ASSERTION(aManager, "bad param");
|
3933
|
+
return NS_GetComponentManager(aManager);
|
3934
|
+
}
|
3935
|
+
|
3936
|
+
/**********************************************/
|
3937
|
+
|
3938
|
+
// The nsIXPCScriptable map declaration that will generate stubs for us...
|
3939
|
+
#define XPC_MAP_CLASSNAME nsXPCComponents
|
3940
|
+
#define XPC_MAP_QUOTED_CLASSNAME "nsXPCComponents"
|
3941
|
+
#define XPC_MAP_WANT_NEWRESOLVE
|
3942
|
+
#define XPC_MAP_WANT_GETPROPERTY
|
3943
|
+
#define XPC_MAP_WANT_SETPROPERTY
|
3944
|
+
#define XPC_MAP_FLAGS nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
3945
|
+
#include "xpc_map_end.h" /* This will #undef the above */
|
3946
|
+
|
3947
|
+
/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
|
3948
|
+
NS_IMETHODIMP
|
3949
|
+
nsXPCComponents::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
3950
|
+
JSContext * cx, JSObject * obj,
|
3951
|
+
jsval id, PRUint32 flags,
|
3952
|
+
JSObject * *objp, PRBool *_retval)
|
3953
|
+
{
|
3954
|
+
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
3955
|
+
if(!rt)
|
3956
|
+
return NS_ERROR_FAILURE;
|
3957
|
+
|
3958
|
+
jsid idid;
|
3959
|
+
uintN attrs = 0;
|
3960
|
+
|
3961
|
+
if(id == rt->GetStringJSVal(XPCJSRuntime::IDX_LAST_RESULT))
|
3962
|
+
{
|
3963
|
+
idid = rt->GetStringID(XPCJSRuntime::IDX_LAST_RESULT);
|
3964
|
+
attrs = JSPROP_READONLY;
|
3965
|
+
}
|
3966
|
+
else if(id == rt->GetStringJSVal(XPCJSRuntime::IDX_RETURN_CODE))
|
3967
|
+
idid = rt->GetStringID(XPCJSRuntime::IDX_RETURN_CODE);
|
3968
|
+
else
|
3969
|
+
return NS_OK;
|
3970
|
+
|
3971
|
+
*objp = obj;
|
3972
|
+
*_retval = JS_DefinePropertyById(cx, obj, idid, JSVAL_VOID, nsnull, nsnull,
|
3973
|
+
JSPROP_ENUMERATE | JSPROP_PERMANENT |
|
3974
|
+
attrs);
|
3975
|
+
return NS_OK;
|
3976
|
+
}
|
3977
|
+
|
3978
|
+
/* PRBool getProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
3979
|
+
NS_IMETHODIMP
|
3980
|
+
nsXPCComponents::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
3981
|
+
JSContext * cx, JSObject * obj,
|
3982
|
+
jsval id, jsval * vp, PRBool *_retval)
|
3983
|
+
{
|
3984
|
+
XPCContext* xpcc = XPCContext::GetXPCContext(cx);
|
3985
|
+
if(!xpcc)
|
3986
|
+
return NS_ERROR_FAILURE;
|
3987
|
+
|
3988
|
+
PRBool doResult = JS_FALSE;
|
3989
|
+
nsresult res;
|
3990
|
+
XPCJSRuntime* rt = xpcc->GetRuntime();
|
3991
|
+
if(id == rt->GetStringJSVal(XPCJSRuntime::IDX_LAST_RESULT))
|
3992
|
+
{
|
3993
|
+
res = xpcc->GetLastResult();
|
3994
|
+
doResult = JS_TRUE;
|
3995
|
+
}
|
3996
|
+
else if(id == rt->GetStringJSVal(XPCJSRuntime::IDX_RETURN_CODE))
|
3997
|
+
{
|
3998
|
+
res = xpcc->GetPendingResult();
|
3999
|
+
doResult = JS_TRUE;
|
4000
|
+
}
|
4001
|
+
|
4002
|
+
nsresult rv = NS_OK;
|
4003
|
+
if(doResult)
|
4004
|
+
{
|
4005
|
+
if(!JS_NewNumberValue(cx, (jsdouble) res, vp))
|
4006
|
+
return NS_ERROR_OUT_OF_MEMORY;
|
4007
|
+
rv = NS_SUCCESS_I_DID_SOMETHING;
|
4008
|
+
}
|
4009
|
+
|
4010
|
+
return rv;
|
4011
|
+
}
|
4012
|
+
|
4013
|
+
/* PRBool setProperty (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); */
|
4014
|
+
NS_IMETHODIMP
|
4015
|
+
nsXPCComponents::SetProperty(nsIXPConnectWrappedNative *wrapper,
|
4016
|
+
JSContext * cx, JSObject * obj, jsval id,
|
4017
|
+
jsval * vp, PRBool *_retval)
|
4018
|
+
{
|
4019
|
+
XPCContext* xpcc = XPCContext::GetXPCContext(cx);
|
4020
|
+
if(!xpcc)
|
4021
|
+
return NS_ERROR_FAILURE;
|
4022
|
+
|
4023
|
+
XPCJSRuntime* rt = xpcc->GetRuntime();
|
4024
|
+
if(!rt)
|
4025
|
+
return NS_ERROR_FAILURE;
|
4026
|
+
|
4027
|
+
if(id == rt->GetStringJSVal(XPCJSRuntime::IDX_RETURN_CODE))
|
4028
|
+
{
|
4029
|
+
nsresult rv;
|
4030
|
+
if(JS_ValueToECMAUint32(cx, *vp, (uint32*)&rv))
|
4031
|
+
{
|
4032
|
+
xpcc->SetPendingResult(rv);
|
4033
|
+
xpcc->SetLastResult(rv);
|
4034
|
+
return NS_SUCCESS_I_DID_SOMETHING;
|
4035
|
+
}
|
4036
|
+
return NS_ERROR_FAILURE;
|
4037
|
+
}
|
4038
|
+
|
4039
|
+
return NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN;
|
4040
|
+
}
|
4041
|
+
|
4042
|
+
// static
|
4043
|
+
JSBool
|
4044
|
+
nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
|
4045
|
+
XPCWrappedNativeScope* aScope,
|
4046
|
+
JSObject* aGlobal)
|
4047
|
+
{
|
4048
|
+
if(!aGlobal)
|
4049
|
+
return JS_FALSE;
|
4050
|
+
|
4051
|
+
nsXPCComponents* components = new nsXPCComponents();
|
4052
|
+
if(!components)
|
4053
|
+
return JS_FALSE;
|
4054
|
+
|
4055
|
+
nsCOMPtr<nsIXPCComponents> cholder(components);
|
4056
|
+
|
4057
|
+
AutoMarkingNativeInterfacePtr iface(ccx);
|
4058
|
+
iface = XPCNativeInterface::GetNewOrUsed(ccx, &NS_GET_IID(nsIXPCComponents));
|
4059
|
+
|
4060
|
+
if(!iface)
|
4061
|
+
return JS_FALSE;
|
4062
|
+
|
4063
|
+
nsCOMPtr<XPCWrappedNative> wrapper;
|
4064
|
+
XPCWrappedNative::GetNewOrUsed(ccx, cholder, aScope, iface, nsnull,
|
4065
|
+
OBJ_IS_NOT_GLOBAL, getter_AddRefs(wrapper));
|
4066
|
+
if(!wrapper)
|
4067
|
+
return JS_FALSE;
|
4068
|
+
|
4069
|
+
aScope->SetComponents(components);
|
4070
|
+
|
4071
|
+
jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS);
|
4072
|
+
JSObject* obj;
|
4073
|
+
|
4074
|
+
return NS_SUCCEEDED(wrapper->GetJSObject(&obj)) &&
|
4075
|
+
obj && JS_DefinePropertyById(ccx, aGlobal, id, OBJECT_TO_JSVAL(obj),
|
4076
|
+
nsnull, nsnull,
|
4077
|
+
JSPROP_PERMANENT | JSPROP_READONLY);
|
4078
|
+
}
|
4079
|
+
|
4080
|
+
/* void lookupMethod (); */
|
4081
|
+
NS_IMETHODIMP nsXPCComponents::LookupMethod()
|
4082
|
+
{
|
4083
|
+
nsresult rv;
|
4084
|
+
nsCOMPtr<nsIXPCComponents_Utils> utils;
|
4085
|
+
|
4086
|
+
NS_WARNING("Components.lookupMethod deprecated, use Components.utils.lookupMethod");
|
4087
|
+
rv = GetUtils(getter_AddRefs(utils));
|
4088
|
+
if (NS_FAILED(rv))
|
4089
|
+
return rv;
|
4090
|
+
|
4091
|
+
return utils->LookupMethod();
|
4092
|
+
}
|
4093
|
+
|
4094
|
+
/* void reportError (); */
|
4095
|
+
NS_IMETHODIMP nsXPCComponents::ReportError()
|
4096
|
+
{
|
4097
|
+
nsresult rv;
|
4098
|
+
nsCOMPtr<nsIXPCComponents_Utils> utils;
|
4099
|
+
|
4100
|
+
NS_WARNING("Components.reportError deprecated, use Components.utils.reportError");
|
4101
|
+
rv = GetUtils(getter_AddRefs(utils));
|
4102
|
+
if (NS_FAILED(rv))
|
4103
|
+
return rv;
|
4104
|
+
|
4105
|
+
return utils->ReportError();
|
4106
|
+
}
|
4107
|
+
|
4108
|
+
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
4109
|
+
/* string canCreateWrapper (in nsIIDPtr iid); */
|
4110
|
+
NS_IMETHODIMP
|
4111
|
+
nsXPCComponents::CanCreateWrapper(const nsIID * iid, char **_retval)
|
4112
|
+
{
|
4113
|
+
// We let anyone do this...
|
4114
|
+
*_retval = xpc_CloneAllAccess();
|
4115
|
+
return NS_OK;
|
4116
|
+
}
|
4117
|
+
|
4118
|
+
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
4119
|
+
NS_IMETHODIMP
|
4120
|
+
nsXPCComponents::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
4121
|
+
{
|
4122
|
+
static const char* allowed[] = { "isSuccessCode", "lookupMethod", nsnull };
|
4123
|
+
*_retval = xpc_CheckAccessList(methodName, allowed);
|
4124
|
+
return NS_OK;
|
4125
|
+
}
|
4126
|
+
|
4127
|
+
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
4128
|
+
NS_IMETHODIMP
|
4129
|
+
nsXPCComponents::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
4130
|
+
{
|
4131
|
+
static const char* allowed[] = { "interfaces", "interfacesByID", "results", nsnull};
|
4132
|
+
*_retval = xpc_CheckAccessList(propertyName, allowed);
|
4133
|
+
return NS_OK;
|
4134
|
+
}
|
4135
|
+
|
4136
|
+
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
4137
|
+
NS_IMETHODIMP
|
4138
|
+
nsXPCComponents::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
4139
|
+
{
|
4140
|
+
// If you have to ask, then the answer is NO
|
4141
|
+
*_retval = nsnull;
|
4142
|
+
return NS_OK;
|
4143
|
+
}
|
4144
|
+
#endif
|