1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is XPConnect Native Wrapper.
16
* The Initial Developer of the Original Code is
17
* Christopher A. Aillon <christopher@aillon.com>.
18
* Portions created by the Initial Developer are Copyright (C) 2002
19
* the Initial Developer. All Rights Reserved.
22
* Christopher A. Aillon <christopher@aillon.com>
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
* Get a wrapper to certain XPConnect wrapped native properties of an
43
* var wrapper = new XPCNativeWrapper(untrusted, 'title', 'getElementById()');
44
* var title = wrapper.title;
45
* var elem = wrapper.getElementById('fooId');
47
* @param aUntrustedObject the untrusted object we want native wrappers for
48
* @param arg1...argN strings of the form 'property' or 'method()' which
49
* denote the property or method names we wish to wrap
50
* @throws NS_ERROR_XPC_BAD_CONVERT_JS if a property or method requested
51
* does not have a native wrapper on
52
* the untrusted object.
53
* @see nsXPCComponents::LookupMethod()
55
function XPCNativeWrapper(aUntrustedObject)
57
this.mUntrustedObject = aUntrustedObject;
59
for (var i = arguments.length - 1; i > 0; --i)
60
this.importXPCNative(arguments[i]);
63
XPCNativeWrapper.prototype =
68
// If we are passed a string like "foo()", ary[2] will be of type string,
69
// and contain "()". If passed "foo", then it will be of type undefined.
70
if (aName.slice(-2) == "()")
71
this._doImportMethod(aName.slice(0, -2));
73
this._doImportProperty(aName);
79
var nativeMethod = Components.lookupMethod(this.mUntrustedObject,
81
this[aMethodName] = function()
83
return nativeMethod.apply(this.mUntrustedObject, arguments);
90
var nativeMethod = Components.lookupMethod(this.mUntrustedObject,
92
var theGetter = function()
94
return nativeMethod.call(this.mUntrustedObject);
96
var theSetter = function(val)
98
return nativeMethod.call(this.mUntrustedObject, val);
101
this.__defineGetter__(aPropName, theGetter);
102
this.__defineSetter__(aPropName, theSetter);