1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/util/NativeJSContainer.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,39 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.util; 1.10 + 1.11 +import org.mozilla.gecko.mozglue.JNITarget; 1.12 + 1.13 +/** 1.14 + * NativeJSContainer is a wrapper around the SpiderMonkey JSAPI to make it possible to 1.15 + * access Javascript objects in Java. 1.16 + * 1.17 + * A container must only be used on the thread it is attached to. To use it on another 1.18 + * thread, call {@link #clone()} to make a copy, and use the copy on the other thread. 1.19 + * When a copy is first used, it becomes attached to the thread using it. 1.20 + */ 1.21 +@JNITarget 1.22 +public final class NativeJSContainer extends NativeJSObject 1.23 +{ 1.24 + private long mNativeObject; 1.25 + 1.26 + private NativeJSContainer(long nativeObject) { 1.27 + mNativeObject = nativeObject; 1.28 + } 1.29 + 1.30 + /** 1.31 + * Make a copy of this container for use by another thread. When the copy is first used, 1.32 + * it becomes attached to the thread using it. 1.33 + */ 1.34 + @Override 1.35 + public native NativeJSContainer clone(); 1.36 + 1.37 + /** 1.38 + * Dispose all associated native objects. Subsequent use of any objects derived from 1.39 + * this container will throw a NullPointerException. 1.40 + */ 1.41 + public native void dispose(); 1.42 +}