1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
\r
2 * The contents of this file are subject to the Mozilla Public License
\r
3 * Version 1.1 (the "License"); you may not use this file except in
\r
4 * compliance with the License. You may obtain a copy of the License at
\r
5 * http://www.mozilla.org/MPL/
\r
7 * Software distributed under the License is distributed on an "AS IS"
\r
8 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
\r
9 * License for the specific language governing rights and limitations
\r
10 * under the License.
\r
12 * The Original Code is Synchronizer.java code, released Sep 27, 2000.
\r
14 * The Initial Developer of the Original Code is Matthias Radestock
\r
15 * <matthias@sorted.org>. Portions created by Matthias Radestock are
\r
16 * Copyright (C) 2000 Matthias Radestock. All Rights Reserved.
\r
19 * Redfig Ltd (http://www.redfig.com)
\r
20 * LShift Ltd (http://www.lshift.net)
\r
22 * Alternatively, the contents of this file may be used under the terms
\r
23 * of the GNU Public License (the "GPL License"), in which case the
\r
24 * provisions of the GPL License are applicable instead of those
\r
25 * above. If you wish to allow use of your version of this file only
\r
26 * under the terms of the GPL License and not to allow others to use
\r
27 * your version of this file under the MPL, indicate your decision by
\r
28 * deleting the provisions above and replace them with the notice and
\r
29 * other provisions required by the GPL License. If you do not delete
\r
30 * the provisions above, a recipient may use your version of this file
\r
31 * under either the MPL or the GPL License.
\r
36 package org.mozilla.javascript;
\r
39 * This class provides support for implementing Java-style synchronized
\r
40 * methods in Javascript.
\r
42 * Synchronized functions are created from ordinary Javascript
\r
43 * functions by the <code>Synchronizer</code> constructor, e.g.
\r
44 * <code>new Packages.org.mozilla.javascript.Synchronizer(fun)</code>.
\r
45 * The resulting object is a function that establishes an exclusive
\r
46 * lock on the <code>this</code> object of its invocation.
\r
48 * The Rhino shell provides a short-cut for the creation of
\r
49 * synchronized methods: <code>sync(fun)</code> has the same effect as
\r
50 * calling the above constructor.
\r
52 * @see org.mozilla.javascript.Delegator
\r
53 * @author Matthias Radestock
\r
56 public class Synchronizer extends Delegator {
\r
59 * Create a new synchronized function from an existing one.
\r
61 * @param obj the existing function
\r
63 public Synchronizer(Scriptable obj) {
\r
68 * @see org.mozilla.javascript.Function#call
\r
70 public Object call(Context cx, Scriptable scope, Scriptable thisObj,
\r
72 throws JavaScriptException {
\r
73 synchronized(thisObj) {
\r
74 return ((Function)obj).call(cx,scope,thisObj,args);
\r