Beispiel #1
0
        /// <summary>
        /// Creates a new <c>Object</c> that stores some external data
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="data">External data that the object will represent. May be null.</param>
        /// <param name="finalizer">A callback for when the object is finalized. May be null.</param>
        /// <returns>The new <c>Object</c></returns>
        public static IeJsValue CreateExternalObject(IntPtr data, JsObjectFinalizeCallback finalizer)
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateExternalObject(data, finalizer, out reference));

            return(reference);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a exception that caused the runtime of the current context to be in the
        /// exception state and resets the exception state for that runtime
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the runtime of the current context is not in an exception state, this API will throw
        /// <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception
        /// indicating that the script was terminated, but it will not clear the exception (the
        /// exception will be cleared if the runtime is re-enabled using
        /// <c>EnableRuntimeExecution</c>).
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <returns>The exception for the runtime of the current context</returns>
        public static IeJsValue GetAndClearException()
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetAndClearException(out reference));

            return(reference);
        }
Beispiel #3
0
        /// <summary>
        /// Releases a reference to a script context
        /// </summary>
        /// <remarks>
        /// Removes a reference to a context that was created by AddRef.
        /// </remarks>
        /// <returns>The object's new reference count</returns>
        public uint Release()
        {
            uint count;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsContextRelease(this, out count));

            return(count);
        }
Beispiel #4
0
        /// <summary>
        /// Tells a runtime to do any idle processing it need to do
        /// </summary>
        /// <remarks>
        /// <para>
        /// If idle processing has been enabled for the current runtime, calling <c>Idle</c> will
        /// inform the current runtime that the host is idle and that the runtime can perform
        /// memory cleanup tasks.
        /// </para>
        /// <para>
        /// <c>Idle</c> will also return the number of system ticks until there will be more idle work
        /// for the runtime to do. Calling <c>Idle</c> before this number of ticks has passed will do
        /// no work.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <returns>The next system tick when there will be more idle work to do. Returns the
        /// maximum number of ticks if there no upcoming idle work to do.</returns>
        public static uint Idle()
        {
            uint ticks;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsIdle(out ticks));

            return(ticks);
        }
Beispiel #5
0
        /// <summary>
        /// Runs a serialized script
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="script">The source code of the serialized script</param>
        /// <param name="buffer">The serialized script</param>
        /// <param name="sourceContext">The cookie identifying the script that can be used by script contexts that have debugging enabled</param>
        /// <param name="sourceName">The location the script came from</param>
        /// <returns>The result of the script, if any</returns>
        public static IeJsValue RunScript(string script, byte[] buffer, JsSourceContext sourceContext, string sourceName)
        {
            IeJsValue result;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsRunSerializedScript(script, buffer, sourceContext, sourceName, out result));

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Defines a new object's own property from a property descriptor
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="propertyId">The ID of the property</param>
        /// <param name="propertyDescriptor">The property descriptor</param>
        /// <returns>Whether the property was defined</returns>
        public bool DefineProperty(IeJsPropertyId propertyId, IeJsValue propertyDescriptor)
        {
            bool result;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsDefineProperty(this, propertyId, propertyDescriptor, out result));

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Retrieve a value at the specified index of an object
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="index">The index to retrieve</param>
        /// <returns>The retrieved value</returns>
        public IeJsValue GetIndexedProperty(IeJsValue index)
        {
            IeJsValue propertyReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetIndexedProperty(this, index, out propertyReference));

            return(propertyReference);
        }
Beispiel #8
0
        /// <summary>
        /// Retrieves a <c>double</c> value of a <c>Number</c> value
        /// </summary>
        /// <remarks>
        /// <para>
        /// This function retrieves the value of a Number value. It will fail with
        /// <c>InvalidArgument</c> if the type of the value is not <c>Number</c>.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <returns>The <c>double</c> value</returns>
        public double ToDouble()
        {
            double value;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsNumberToDouble(this, out value));

            return(value);
        }
Beispiel #9
0
        /// <summary>
        /// Retrieves a object representation of an <c>Object</c> value
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The object representation of the value</returns>
        public object ToObject()
        {
            object value;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsValueToVariant(this, out value));

            return(value);
        }
Beispiel #10
0
        /// <summary>
        /// Adds a reference to the object
        /// </summary>
        /// <remarks>
        /// This only needs to be called on objects that are not going to be stored somewhere on
        /// the stack. Calling AddRef ensures that the JavaScript object the value refers to will not be freed
        /// until Release is called
        /// </remarks>
        /// <returns>The object's new reference count</returns>
        public uint AddRef()
        {
            uint count;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsAddRef(this, out count));

            return(count);
        }
Beispiel #11
0
        /// <summary>
        /// Retrieves a <c>bool</c> value of a <c>Boolean</c> value
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The converted value</returns>
        public bool ToBoolean()
        {
            bool value;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsBooleanToBool(this, out value));

            return(value);
        }
Beispiel #12
0
        /// <summary>
        /// Creates a new JavaScript URIError error object
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="message">Message for the error object</param>
        /// <returns>The new error object</returns>
        public static IeJsValue CreateUriError(IeJsValue message)
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateURIError(message, out reference));

            return(reference);
        }
Beispiel #13
0
        /// <summary>
        /// Creates a JavaScript array object
        /// </summary>
        /// <remarks>
        /// Requires an active script context
        /// </remarks>
        /// <param name="length">The initial length of the array</param>
        /// <returns>The new array object</returns>
        public static IeJsValue CreateArray(uint length)
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateArray(length, out reference));

            return(reference);
        }
Beispiel #14
0
        /// <summary>
        /// Creates a new JavaScript function
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="function">The method to call when the function is invoked</param>
        /// <param name="callbackData">Data to be provided to all function callbacks</param>
        /// <returns>The new function object</returns>
        public static IeJsValue CreateFunction(IeJsNativeFunction function, IntPtr callbackData)
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateFunction(function, callbackData, out reference));

            return(reference);
        }
Beispiel #15
0
        /// <summary>
        /// Gets a object's property
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="id">The ID of the property</param>
        /// <returns>The value of the property</returns>
        public IeJsValue GetProperty(IeJsPropertyId id)
        {
            IeJsValue propertyReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetProperty(this, id, out propertyReference));

            return(propertyReference);
        }
Beispiel #16
0
        /// <summary>
        /// Converts a value to <c>Boolean</c> using regular JavaScript semantics
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The converted value</returns>
        public IeJsValue ConvertToBoolean()
        {
            IeJsValue booleanReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsConvertValueToBoolean(this, out booleanReference));

            return(booleanReference);
        }
Beispiel #17
0
        /// <summary>
        /// Deletes a object's property
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="propertyId">The ID of the property</param>
        /// <param name="useStrictRules">The property set should follow strict mode rules</param>
        /// <returns>Whether the property was deleted</returns>
        public IeJsValue DeleteProperty(IeJsPropertyId propertyId, bool useStrictRules)
        {
            IeJsValue returnReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsDeleteProperty(this, propertyId, useStrictRules, out returnReference));

            return(returnReference);
        }
Beispiel #18
0
        /// <summary>
        /// Converts a value to <c>Number</c> using regular JavaScript semantics
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The converted value</returns>
        public IeJsValue ConvertToNumber()
        {
            IeJsValue numberReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsConvertValueToNumber(this, out numberReference));

            return(numberReference);
        }
Beispiel #19
0
        /// <summary>
        /// Test if an object has a value at the specified index
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="index">The index to test</param>
        /// <returns>Whether the object has an value at the specified index</returns>
        public bool HasIndexedProperty(IeJsValue index)
        {
            bool hasProperty;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsHasIndexedProperty(this, index, out hasProperty));

            return(hasProperty);
        }
Beispiel #20
0
        /// <summary>
        /// Converts a value to <c>String</c> using regular JavaScript semantics
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The converted value</returns>
        public IeJsValue ConvertToString()
        {
            IeJsValue stringReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsConvertValueToString(this, out stringReference));

            return(stringReference);
        }
Beispiel #21
0
        /// <summary>
        /// Compare two JavaScript values for strict equality
        /// </summary>
        /// <remarks>
        /// <para>
        /// This function is equivalent to the "===" operator in JavaScript.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <param name="other">The object to compare</param>
        /// <returns>Whether the values are strictly equal</returns>
        public bool StrictEquals(IeJsValue other)
        {
            bool equals;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsStrictEquals(this, other, out equals));

            return(equals);
        }
Beispiel #22
0
        /// <summary>
        /// Converts a value to <c>Object</c> using regular JavaScript semantics
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The converted value</returns>
        public IeJsValue ConvertToObject()
        {
            IeJsValue objectReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsConvertValueToObject(this, out objectReference));

            return(objectReference);
        }
Beispiel #23
0
        /// <summary>
        /// Parses a script and returns a <c>Function</c> representing the script
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="script">The script to parse</param>
        /// <param name="sourceContext">The cookie identifying the script that can be used
        /// by script contexts that have debugging enabled</param>
        /// <param name="sourceName">The location the script came from</param>
        /// <returns>The <c>Function</c> representing the script code</returns>
        public static IeJsValue ParseScript(string script, JsSourceContext sourceContext, string sourceName)
        {
            IeJsValue result;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsParseScript(script, sourceContext, sourceName, out result));

            return(result);
        }
Beispiel #24
0
        /// <summary>
        /// Gets a property descriptor for an object's own property
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="propertyId">The ID of the property</param>
        /// <returns>The property descriptor</returns>
        public IeJsValue GetOwnPropertyDescriptor(IeJsPropertyId propertyId)
        {
            IeJsValue descriptorReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetOwnPropertyDescriptor(this, propertyId, out descriptorReference));

            return(descriptorReference);
        }
Beispiel #25
0
        /// <summary>
        /// Serializes a parsed script to a buffer than can be reused
        /// </summary>
        /// <remarks>
        /// <para>
        /// SerializeScript parses a script and then stores the parsed form of the script in a
        /// runtime-independent format. The serialized script then can be deserialized in any
        /// runtime without requiring the script to be re-parsed.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <param name="script">The script to serialize</param>
        /// <param name="buffer">The buffer to put the serialized script into. Can be null.</param>
        /// <returns>The size of the buffer, in bytes, required to hold the serialized script</returns>
        public static ulong SerializeScript(string script, byte[] buffer)
        {
            var bufferSize = (ulong)buffer.Length;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsSerializeScript(script, buffer, ref bufferSize));

            return(bufferSize);
        }
Beispiel #26
0
        /// <summary>
        /// Gets a list of all properties on the object
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The array of property names</returns>
        public IeJsValue GetOwnPropertyNames()
        {
            IeJsValue propertyNamesReference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsGetOwnPropertyNames(this, out propertyNamesReference));

            return(propertyNamesReference);
        }
Beispiel #27
0
        /// <summary>
        /// Enumerates a heap of the current context
        /// </summary>
        /// <remarks>
        /// <para>
        /// While the heap is being enumerated, the current context cannot be removed, and all calls to
        /// modify the state of the context will fail until the heap enumerator is released.
        /// </para>
        /// <para>
        /// Requires an active script context.
        /// </para>
        /// </remarks>
        /// <returns>The heap enumerator</returns>
        public static IActiveScriptProfilerHeapEnum EnumerateHeap()
        {
            IActiveScriptProfilerHeapEnum enumerator;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsEnumerateHeap(out enumerator));

            return(enumerator);
        }
Beispiel #28
0
        /// <summary>
        /// Determines whether an object has a property
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <param name="propertyId">The ID of the property</param>
        /// <returns>Whether the object (or a prototype) has the property</returns>
        public bool HasProperty(IeJsPropertyId propertyId)
        {
            bool hasProperty;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsHasProperty(this, propertyId, out hasProperty));

            return(hasProperty);
        }
        /// <summary>
        /// Creates a new runtime
        /// </summary>
        /// <param name="attributes">The attributes of the runtime to be created</param>
        /// <param name="version">The version of the runtime to be created</param>
        /// <param name="threadServiceCallback">The thread service for the runtime. Can be null.</param>
        /// <returns>The runtime created</returns>
        public static IeJsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version, JsThreadServiceCallback threadServiceCallback)
        {
            IeJsRuntime handle;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateRuntime(attributes, version, threadServiceCallback, out handle));

            return(handle);
        }
Beispiel #30
0
        /// <summary>
        /// Creates a new <c>Object</c>
        /// </summary>
        /// <remarks>
        /// Requires an active script context.
        /// </remarks>
        /// <returns>The new <c>Object</c></returns>
        public static IeJsValue CreateObject()
        {
            IeJsValue reference;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateObject(out reference));

            return(reference);
        }