本文整理汇总了C#中Jurassic.Library.ObjectInstance类的典型用法代码示例。如果您正苦于以下问题:C# ObjectInstance类的具体用法?C# ObjectInstance怎么用?C# ObjectInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectInstance类属于Jurassic.Library命名空间,在下文中一共展示了ObjectInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowTypeErrorFunction
/// <summary>
/// Creates a new ThrowTypeErrorFunction instance.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="message"> The TypeError message. </param>
internal ThrowTypeErrorFunction(ObjectInstance prototype, string message)
: base(prototype)
{
this.FastSetProperty("length", 0);
this.IsExtensible = false;
this.message = message;
}
示例2: DataViewInstance
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new DataView instance.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="buffer"> An existing ArrayBuffer to use as the storage for the new
/// DataView object. </param>
/// <param name="byteOffset"> The offset, in bytes, to the first byte in the specified
/// buffer for the new view to reference. If not specified, the view of the buffer will
/// start with the first byte. </param>
/// <param name="byteLength"> The number of elements in the byte array. If unspecified,
/// length of the view will match the buffer's length. </param>
internal DataViewInstance(ObjectInstance prototype, ArrayBufferInstance buffer, int byteOffset, int byteLength)
: base(prototype)
{
this.buffer = buffer;
this.byteOffset = byteOffset;
this.byteLength = byteLength;
}
示例3: JSONObject
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new JSON object.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
internal JSONObject(ObjectInstance prototype)
: base(prototype)
{
var properties = GetDeclarativeProperties(Engine);
properties.Add(new PropertyNameAndValue(Engine.Symbol.ToStringTag, "JSON", PropertyAttributes.Configurable));
FastSetProperties(properties);
}
示例4: ClrStubFunction
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a function which calls a .NET method, with no name or length.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="call"> The delegate to call when calling the JS method. </param>
internal ClrStubFunction(ObjectInstance prototype, Func<ScriptEngine, object, object[], object> call)
: base(prototype)
{
// Let's not even bother with setting the name and length!
// Use sparingly.
this.callBinder = call;
}
示例5: LoaderInstance
/// <summary>
/// Initializes a new instance of the <see cref="LoaderInstance"/> class.
/// </summary>
/// <param name="prototype">The prototype.</param>
/// <param name="scriptRunner">The script runner.</param>
public LoaderInstance(ObjectInstance prototype, ScriptRunner scriptRunner)
: base(prototype)
{
this.scriptRunner = scriptRunner;
this.webClient = new WebClient();
this.PopulateFunctions();
}
示例6: AddObject
public void AddObject(string name, ObjectInstance obj)
{
if(name != null && obj != null)
{
engine.SetGlobalValue(name, obj);
}
}
示例7: ClrFunction
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new instance of a built-in constructor function.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="name"> The name of the function. </param>
/// <param name="instancePrototype"> </param>
protected ClrFunction(ObjectInstance prototype, string name, ObjectInstance instancePrototype)
: base(prototype)
{
if (name == null)
throw new ArgumentNullException("name");
if (instancePrototype == null)
throw new ArgumentNullException("instancePrototype");
// This is a constructor so ignore the "this" parameter when the function is called.
thisBinding = this;
// Search through every method in this type looking for [JSCallFunction] and [JSConstructorFunction] attributes.
var callBinderMethods = new List<JSBinderMethod>(1);
var constructBinderMethods = new List<JSBinderMethod>(1);
var methods = this.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var method in methods)
{
// Search for the [JSCallFunction] and [JSConstructorFunction] attributes.
var callAttribute = (JSCallFunctionAttribute) Attribute.GetCustomAttribute(method, typeof(JSCallFunctionAttribute));
var constructorAttribute = (JSConstructorFunctionAttribute)Attribute.GetCustomAttribute(method, typeof(JSConstructorFunctionAttribute));
// Can't declare both attributes.
if (callAttribute != null && constructorAttribute != null)
throw new InvalidOperationException("Methods cannot be marked with both [JSCallFunction] and [JSConstructorFunction].");
if (callAttribute != null)
{
// Method is marked with [JSCallFunction]
callBinderMethods.Add(new JSBinderMethod(method, callAttribute.Flags));
}
else if (constructorAttribute != null)
{
var binderMethod = new JSBinderMethod(method, constructorAttribute.Flags);
constructBinderMethods.Add(binderMethod);
// Constructors must return ObjectInstance or a derived type.
if (typeof(ObjectInstance).IsAssignableFrom(binderMethod.ReturnType) == false)
throw new InvalidOperationException(string.Format("Constructors must return {0} (or a derived type).", typeof(ObjectInstance).Name));
}
}
// Initialize the Call function.
if (callBinderMethods.Count > 0)
this.callBinder = new JSBinder(callBinderMethods);
else
this.callBinder = new JSBinder(new JSBinderMethod(new Func<object>(() => Undefined.Value).Method));
// Initialize the Construct function.
if (constructBinderMethods.Count > 0)
this.constructBinder = new JSBinder(constructBinderMethods);
else
this.constructBinder = new JSBinder(new JSBinderMethod(new Func<ObjectInstance>(() => this.Engine.Object.Construct()).Method));
// Add function properties.
this.FastSetProperty("name", name);
this.FastSetProperty("length", this.callBinder.FunctionLength);
this.FastSetProperty("prototype", instancePrototype);
instancePrototype.FastSetProperty("constructor", this, PropertyAttributes.NonEnumerable);
}
示例8: BooleanConstructor
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new Boolean object.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
internal BooleanConstructor(ObjectInstance prototype)
: base(prototype, __STUB__Construct, __STUB__Call)
{
// Initialize the constructor properties.
var properties = new List<PropertyNameAndValue>(3);
InitializeConstructorProperties(properties, "Boolean", 1, BooleanInstance.CreatePrototype(Engine, this));
FastSetProperties(properties);
}
示例9: WeakMapConstructor
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new map constructor.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
internal WeakMapConstructor(ObjectInstance prototype)
: base(prototype, __STUB__Construct, __STUB__Call)
{
// Initialize the constructor properties.
var properties = new List<PropertyNameAndValue>();
InitializeConstructorProperties(properties, "WeakMap", 0, WeakMapInstance.CreatePrototype(Engine, this));
FastSetProperties(properties);
}
示例10: JsEventObject
/// <summary>
/// Initializes a new instance of the <see cref="JsEventObject"/> class.
/// </summary>
/// <param name="prototype">The prototype.</param>
/// <param name="runner">The runner.</param>
public JsEventObject(ObjectInstance prototype, ScriptRunner runner)
: base(prototype)
{
this.runner = runner;
this.events = new Dictionary<string, List<FunctionInstance>>();
PopulateFunctions(typeof(JsEventObject));
}
示例11: ThrowTypeErrorFunction
/// <summary>
/// Creates a new ThrowTypeErrorFunction instance.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="message"> The TypeError message. </param>
internal ThrowTypeErrorFunction(ObjectInstance prototype, string message)
: base(prototype)
{
this.FastSetProperty("name", "ThrowTypeError", PropertyAttributes.Configurable);
this.FastSetProperty("length", 0, PropertyAttributes.Configurable);
this.IsExtensible = false;
this.message = message;
}
示例12: ObjectConstructor
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new Object object.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="instancePrototype"> The prototype for instances created by this function. </param>
internal ObjectConstructor(ObjectInstance prototype, ObjectInstance instancePrototype)
: base(prototype, __STUB__Construct, __STUB__Call)
{
// Initialize the constructor properties.
var properties = GetDeclarativeProperties(Engine);
InitializeConstructorProperties(properties, "Object", 1, instancePrototype);
FastSetProperties(properties);
}
示例13: SetIterator
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new set iterator.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="set"> The set to iterate over. </param>
/// <param name="list"> The linked list to iterate over. </param>
/// <param name="kind"> The type of values to return. </param>
internal SetIterator(ObjectInstance prototype, SetInstance set, LinkedList<object> list, Kind kind)
: base(prototype)
{
this.set = set;
this.set.BeforeDelete += Set_BeforeDelete;
this.list = list;
this.kind = kind;
}
示例14: XMLDocInstance
public XMLDocInstance(ObjectInstance prototype, string path)
: this(prototype)
{
_doc = new XmlDocument();
_path = path;
_doc.AppendChild(_doc.CreateXmlDeclaration("1.0", null, null));
_doc.AppendChild(_doc.CreateComment("Generated by Sphere SFML XML Content Serializer v1.0"));
}
示例15: ErrorConstructor
// INITIALIZATION
//_________________________________________________________________________________________
/// <summary>
/// Creates a new derived error function.
/// </summary>
/// <param name="prototype"> The next object in the prototype chain. </param>
/// <param name="type"> The type of error, e.g. Error, RangeError, etc. </param>
internal ErrorConstructor(ObjectInstance prototype, ErrorType type)
: base(prototype, __STUB__Construct, __STUB__Call)
{
// Initialize the constructor properties.
var properties = new List<PropertyNameAndValue>(3);
InitializeConstructorProperties(properties, type.ToString(), 1, ErrorInstance.CreatePrototype(Engine, this, type));
FastSetProperties(properties);
}