Esempio n. 1
0
        private bool TryGetResult(EcmaPropertyKey propertyKey, EcmaValue value, out bool done, out EcmaValue result)
        {
            RuntimeObject method = target.GetMethod(propertyKey);

            if (method == null)
            {
                result = value;
                done   = true;
                return(false);
            }
            EcmaValue obj = method.Call(target, value);

            Guard.ArgumentIsObject(obj);
            done   = obj[WellKnownProperty.Done].ToBoolean();
            result = obj[WellKnownProperty.Value];
            return(true);
        }
Esempio n. 2
0
        public static bool InstanceOf(this EcmaValue thisValue, EcmaValue constructor)
        {
            if (constructor.Type != EcmaValueType.Object)
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotFunction);
            }
            RuntimeObject obj           = constructor.ToObject();
            RuntimeObject instOfHandler = obj.GetMethod(Symbol.HasInstance);

            if (instOfHandler != null)
            {
                return(instOfHandler.Call(constructor, thisValue).ToBoolean());
            }
            if (!constructor.IsCallable)
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotFunction);
            }
            return(obj.HasInstance(thisValue.ToObject()));
        }
Esempio n. 3
0
        public static void VerifyMatch(EcmaValue pattern, EcmaValue flags, EcmaValue input, object[] expected, int index)
        {
            EcmaValue re = default;

            That(() => re = RegExp.Construct(pattern, flags), Throws.Nothing, FormatArguments(Undefined, new[] { pattern, flags }));

            RuntimeObject fn = TestContext.CurrentContext.Test.Arguments.FirstOrDefault() as RuntimeObject;

            if (fn == null || fn.IsIntrinsicFunction(WellKnownObject.RegExpPrototype, "test"))
            {
                fn = re.ToObject().GetMethod("exec");
            }
            EcmaValue actual = fn.Call(re, input);

            if (expected != null)
            {
                That(actual, Is.EquivalentTo(expected), "RegExp={0}, Input={1}", re, input);
                That(actual["index"], Is.EqualTo(index), "RegExp={0}, Input={1}", re, input);
            }
            else
            {
                That(actual, Is.EqualTo(Null), "RegExp={0}, Input={1}", re, input);
            }
        }
Esempio n. 4
0
 private void ResolveSelf(EcmaValue value, bool finalize)
 {
     if (value.Type == EcmaValueType.Object)
     {
         RuntimeObject obj = value.ToObject();
         if (obj == this)
         {
             SetStateFinalize(PromiseState.Rejected, new EcmaTypeErrorException(InternalString.Error.PromiseSelfResolution).ToValue());
             return;
         }
         try {
             RuntimeObject then = obj.GetMethod(WellKnownProperty.Then);
             if (then != null)
             {
                 then.Call(value, (PromiseResolver)ResolveSelf, (PromiseResolver)RejectSelf);
                 return;
             }
         } catch (Exception ex) {
             SetStateFinalize(PromiseState.Rejected, EcmaValueUtility.GetValueFromException(ex));
             return;
         }
     }
     SetState(PromiseState.Fulfilled, value, finalize);
 }
Esempio n. 5
0
 internal void InitWithExecutor(RuntimeObject callback)
 {
     Guard.ArgumentNotNull(callback, "callback");
     ExecuteCallback((a, b) => callback.Call(EcmaValue.Undefined, a, b));
 }