Exemplo n.º 1
0
            public BlittableObjectProperty(BlittableObjectInstance parent, string property)
                : base(PropertyFlag.CustomJsValue | PropertyFlag.Writable | PropertyFlag.WritableSet | PropertyFlag.Enumerable | PropertyFlag.EnumerableSet)
            {
                _parent   = parent;
                _property = property;

                if (TryGetValueFromLucene(_parent, _property, out _value) == false)
                {
                    if (_parent.Projection?.MustExtractFromIndex == true)
                    {
                        if (_parent.Projection.MustExtractOrThrow)
                        {
                            _parent.Projection.ThrowCouldNotExtractFieldFromIndexBecauseIndexDoesNotContainSuchFieldOrFieldValueIsNotStored(property);
                        }

                        _value = JsValue.Undefined;
                        return;
                    }

                    if (TryGetValueFromDocument(_parent, _property, out _value) == false)
                    {
                        if (_parent.Projection?.MustExtractFromDocument == true)
                        {
                            if (_parent.Projection.MustExtractOrThrow)
                            {
                                _parent.Projection.ThrowCouldNotExtractFieldFromDocumentBecauseDocumentDoesNotContainSuchField(_parent.DocumentId, property);
                            }
                        }

                        _value = JsValue.Undefined;
                    }
                }
            }
Exemplo n.º 2
0
        private void WriteBlittableInstance(BlittableObjectInstance obj, bool isRoot, bool filterProperties)
        {
            if (obj.DocumentId != null &&
                _usageMode == BlittableJsonDocumentBuilder.UsageMode.None)
            {
                var metadata = obj.GetOrCreate(Constants.Documents.Metadata.Key);
                metadata.Put(Constants.Documents.Metadata.Id, obj.DocumentId, false);
            }
            if (obj.Blittable != null)
            {
                foreach (var propertyIndex in obj.Blittable.GetPropertiesByInsertionOrder())
                {
                    var prop = new BlittableJsonReaderObject.PropertyDetails();

                    obj.Blittable.GetPropertyByIndex(propertyIndex, ref prop);

                    var existInObject = obj.OwnValues.Remove(prop.Name, out var modifiedValue);

                    if (existInObject == false && obj.Deletes?.Contains(prop.Name) == true)
                    {
                        continue;
                    }

                    if (ShouldFilterProperty(filterProperties, prop.Name))
                    {
                        continue;
                    }

                    _writer.WritePropertyName(prop.Name);

                    if (existInObject && modifiedValue.Changed)
                    {
                        WriteJsonValue(obj, isRoot, prop.Name, modifiedValue.Value);
                    }
                    else
                    {
                        _writer.WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
                    }
                }
            }

            foreach (var modificationKvp in obj.OwnValues)
            {
                var propertyName = modificationKvp.Key;
                if (ShouldFilterProperty(filterProperties, propertyName))
                {
                    continue;
                }

                if (modificationKvp.Value.Changed == false)
                {
                    continue;
                }

                _writer.WritePropertyName(propertyName);
                var blittableObjectProperty = modificationKvp.Value;
                WriteJsonValue(obj, isRoot, propertyName, blittableObjectProperty.Value);
            }
        }
Exemplo n.º 3
0
            private bool TryGetValueFromDocument(BlittableObjectInstance parent, string property, out JsValue value)
            {
                value = null;

                var index = parent.Blittable?.GetPropertyIndex(property);

                if (index == null || index == -1)
                {
                    return(false);
                }

                var propertyDetails = new BlittableJsonReaderObject.PropertyDetails();

                parent.Blittable.GetPropertyByIndex(index.Value, ref propertyDetails, true);

                value = TranslateToJs(parent, property, propertyDetails.Token, propertyDetails.Value);
                return(true);
            }
Exemplo n.º 4
0
            public BlittableObjectProperty(BlittableObjectInstance parent, string property)
                : base(PropertyFlag.CustomJsValue | PropertyFlag.Writable | PropertyFlag.WritableSet | PropertyFlag.Enumerable | PropertyFlag.EnumerableSet)
            {
                _parent   = parent;
                _property = property;

                if (TryGetValueFromLucene(_parent, _property, out _value) == false)
                {
                    var index = _parent.Blittable?.GetPropertyIndex(_property);
                    if (index == null || index == -1)
                    {
                        _value = JsValue.Undefined;
                    }
                    else
                    {
                        _value = GetPropertyValue(_property, index.Value);
                    }
                }
            }
Exemplo n.º 5
0
            public BlittableObjectProperty(BlittableObjectInstance parent, string property)
                : base(null, true, null, null)
            {
                _parent   = parent;
                _property = property;
                var index = _parent.Blittable?.GetPropertyIndex(_property);

                if (index == null || index == -1)
                {
                    if (_parent.LuceneDocument != null)
                    {
                        // if it isn't on the document, check if it is stored in the index?
                        var fieldType = QueryResultRetrieverBase.GetFieldType(property, _parent.LuceneDocument);
                        var values    = _parent.LuceneDocument.GetValues(property, _parent.LuceneState);
                        if (fieldType.IsArray)
                        {
                            Value = JsValue.FromObject(_parent.Engine, values);
                        }
                        else if (values.Length == 1)
                        {
                            Value = fieldType.IsJson
                                ? new JsonParser(_parent.Engine).Parse(values[0])
                                : new JsValue(values[0]);
                        }
                        else
                        {
                            Value = JsValue.Undefined;
                        }
                    }
                    else
                    {
                        Value = JsValue.Undefined;
                    }
                }
                else
                {
                    Value = GetPropertyValue(_property, index.Value);
                }
            }
Exemplo n.º 6
0
            private bool TryGetValueFromLucene(BlittableObjectInstance parent, string property, out JsValue value)
            {
                value = null;

                if (parent.LuceneDocument == null || parent.LuceneIndexFields == null)
                {
                    return(false);
                }

                if (parent.LuceneIndexFields.TryGetValue(_property, out var indexField) == false && parent.LuceneAnyDynamicIndexFields == false)
                {
                    return(false);
                }

                if (indexField != null && indexField.Storage == FieldStorage.No)
                {
                    return(false);
                }

                var fieldType = QueryResultRetrieverBase.GetFieldType(property, parent.LuceneDocument);

                if (fieldType.IsArray)
                {
                    // here we need to perform a manipulation in order to generate the object from the data
                    if (fieldType.IsJson)
                    {
                        Lucene.Net.Documents.Field[] propertyFields = parent.LuceneDocument.GetFields(property);

                        JsValue[] arrayItems =
                            new JsValue[propertyFields.Length];

                        for (int i = 0; i < propertyFields.Length; i++)
                        {
                            var field       = propertyFields[i];
                            var stringValue = field.StringValue(parent.LuceneState);

                            var itemAsBlittable = parent.Blittable._context.ReadForMemory(stringValue, field.Name);

                            arrayItems[i] = TranslateToJs(parent, field.Name, BlittableJsonToken.StartObject, itemAsBlittable);
                        }

                        value = FromObject(parent.Engine, arrayItems);
                        return(true);
                    }

                    var values = parent.LuceneDocument.GetValues(property, parent.LuceneState);
                    value = FromObject(parent.Engine, values);
                    return(true);
                }

                var fieldable = _parent.LuceneDocument.GetFieldable(property);

                if (fieldable == null)
                {
                    return(false);
                }

                var val = fieldable.StringValue(_parent.LuceneState);

                if (fieldType.IsJson)
                {
                    BlittableJsonReaderObject valueAsBlittable = parent.Blittable._context.ReadForMemory(val, property);
                    value = TranslateToJs(parent, property, BlittableJsonToken.StartObject, valueAsBlittable);
                    return(true);
                }

                if (fieldable.IsTokenized == false)
                {
                    // NULL_VALUE and EMPTY_STRING fields aren't tokenized
                    // this will prevent converting fields with a "NULL_VALUE" string to null
                    switch (val)
                    {
                    case Client.Constants.Documents.Indexing.Fields.NullValue:
                        value = JsValue.Null;
                        return(true);

                    case Client.Constants.Documents.Indexing.Fields.EmptyString:
                        value = string.Empty;
                        return(true);
                    }
                }

                if (fieldType.IsNumeric)
                {
                    if (long.TryParse(val, out var valueAsLong))
                    {
                        value = valueAsLong;
                    }
                    else if (double.TryParse(val, out var valueAsDouble))
                    {
                        value = valueAsDouble;
                    }
                    else
                    {
                        throw new InvalidOperationException($"Recognized field '{property}' as numeric but was unable to parse its value to 'long' or 'double'. " +
                                                            $"documentId = '{parent.DocumentId}', value = {val}.");
                    }
                }
                else
                {
                    value = val;
                }

                return(true);
            }
Exemplo n.º 7
0
        private void WriteBlittableInstance(BlittableObjectInstance obj, bool isRoot, bool filterProperties)
        {
            HashSet <string> modifiedProperties = null;

            if (obj.DocumentId != null &&
                _usageMode == BlittableJsonDocumentBuilder.UsageMode.None)
            {
                var metadata = obj.GetOrCreate(Constants.Documents.Metadata.Key);
                metadata.Set(Constants.Documents.Metadata.Id, obj.DocumentId, false);
            }
            if (obj.Blittable != null)
            {
                var propertiesByInsertionOrder = obj.Blittable.GetPropertiesByInsertionOrder();
                for (int i = 0; i < propertiesByInsertionOrder.Properties.Count; i++)
                {
                    var prop      = new BlittableJsonReaderObject.PropertyDetails();
                    var propIndex = propertiesByInsertionOrder.Properties[i];
                    obj.Blittable.GetPropertyByIndex(propIndex, ref prop);

                    BlittableObjectInstance.BlittableObjectProperty modifiedValue = default;
                    JsValue key           = prop.Name.ToString();
                    var     existInObject = obj.OwnValues?
                                            .TryGetValue(key, out modifiedValue) == true;

                    if (existInObject == false && obj.Deletes?.Contains(key) == true)
                    {
                        continue;
                    }

                    if (existInObject)
                    {
                        modifiedProperties ??= new HashSet <string>();

                        modifiedProperties.Add(prop.Name);
                    }

                    if (ShouldFilterProperty(filterProperties, prop.Name))
                    {
                        continue;
                    }

                    _writer.WritePropertyName(prop.Name);

                    if (existInObject && modifiedValue.Changed)
                    {
                        WriteJsonValue(obj, isRoot, prop.Name, modifiedValue.Value);
                    }
                    else
                    {
                        _writer.WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
                    }
                }
            }

            if (obj.OwnValues == null)
            {
                return;
            }

            foreach (var modificationKvp in obj.OwnValues)
            {
                //We already iterated through those properties while iterating the original properties set.
                if (modifiedProperties != null && modifiedProperties.Contains(modificationKvp.Key.AsString()))
                {
                    continue;
                }

                var propertyName         = modificationKvp.Key;
                var propertyNameAsString = propertyName.AsString();
                if (ShouldFilterProperty(filterProperties, propertyNameAsString))
                {
                    continue;
                }

                if (modificationKvp.Value.Changed == false)
                {
                    continue;
                }

                _writer.WritePropertyName(propertyNameAsString);
                var blittableObjectProperty = modificationKvp.Value;
                WriteJsonValue(obj, isRoot, propertyNameAsString, blittableObjectProperty.Value);
            }
        }
            public BlittableObjectProperty(BlittableObjectInstance parent, string property)
                : base(PropertyFlag.CustomJsValue | PropertyFlag.Writable | PropertyFlag.WritableSet | PropertyFlag.Enumerable | PropertyFlag.EnumerableSet)
            {
                _parent   = parent;
                _property = property;
                var index = _parent.Blittable?.GetPropertyIndex(_property);

                if (index == null || index == -1)
                {
                    if (_parent.LuceneDocument != null)
                    {
                        // if it isn't on the document, check if it is stored in the index?
                        var fieldType = QueryResultRetrieverBase.GetFieldType(property, _parent.LuceneDocument);
                        var values    = _parent.LuceneDocument.GetValues(property, _parent.LuceneState);
                        if (fieldType.IsArray)
                        {
                            // here we need to perform a manipulation in order to generate the object from the
                            // data
                            if (fieldType.IsJson)
                            {
                                Lucene.Net.Documents.Field[] propertyFields = _parent.LuceneDocument.GetFields(property);

                                JsValue[] arrayItems =
                                    new JsValue[propertyFields.Length];

                                for (int i = 0; i < propertyFields.Length; i++)
                                {
                                    var field       = propertyFields[i];
                                    var stringValue = field.StringValue(parent.LuceneState);

                                    var maxByteSize     = Encodings.Utf8.GetByteCount(stringValue);
                                    var itemAsBlittable = parent.Blittable._context.ReadForMemory(stringValue, field.Name);

                                    arrayItems[i] = TranslateToJs(_parent, field.Name, BlittableJsonToken.StartObject, itemAsBlittable);
                                }

                                _value = JsValue.FromObject(_parent.Engine, arrayItems);
                            }
                            else
                            {
                                _value = JsValue.FromObject(_parent.Engine, values);
                            }
                        }
                        else if (values.Length == 1)
                        {
                            if (fieldType.IsJson)
                            {
                                BlittableJsonReaderObject valueAsBlittable = parent.Blittable._context.ReadForMemory(values[0], property);
                                _value = TranslateToJs(_parent, property, BlittableJsonToken.StartObject, valueAsBlittable);
                            }
                            else
                            {
                                var value = values[0];
                                switch (value)
                                {
                                case Client.Constants.Documents.Indexing.Fields.NullValue:
                                    value = null;
                                    break;

                                case Client.Constants.Documents.Indexing.Fields.EmptyString:
                                    value = string.Empty;
                                    break;
                                }
                                _value = value;
                            }
                        }
                        else
                        {
                            _value = JsValue.Undefined;
                        }
                    }
                    else
                    {
                        _value = JsValue.Undefined;
                    }
                }
                else
                {
                    _value = GetPropertyValue(_property, index.Value);
                }
            }
Exemplo n.º 9
0
        internal JsValue TranslateToJs(Engine engine, JsonOperationContext context, object o)
        {
            if (o is Tuple <Document, Lucene.Net.Documents.Document, IState, Dictionary <string, IndexField>, bool?> t)
            {
                var d = t.Item1;
                return(new BlittableObjectInstance(engine, null, Clone(d.Data, context), d.Id, d.LastModified, d.ChangeVector)
                {
                    LuceneDocument = t.Item2,
                    LuceneState = t.Item3,
                    LuceneIndexFields = t.Item4,
                    LuceneAnyDynamicIndexFields = t.Item5 ?? false
                });
            }
            if (o is Document doc)
            {
                return(new BlittableObjectInstance(engine, null, Clone(doc.Data, context), doc.Id, doc.LastModified));
            }
            if (o is DocumentConflict dc)
            {
                return(new BlittableObjectInstance(engine, null, Clone(dc.Doc, context), dc.Id, dc.LastModified));
            }

            if (o is BlittableJsonReaderObject json)
            {
                return(new BlittableObjectInstance(engine, null, Clone(json, context), null, null));
            }

            if (o == null)
            {
                return(Undefined.Instance);
            }
            if (o is long lng)
            {
                return(lng);
            }
            if (o is BlittableJsonReaderArray bjra)
            {
                var jsArray = engine.Array.Construct(Array.Empty <JsValue>());
                var args    = new JsValue[1];
                for (var i = 0; i < bjra.Length; i++)
                {
                    args[0] = TranslateToJs(engine, context, bjra[i]);
                    engine.Array.PrototypeObject.Push(jsArray, args);
                }
                return(jsArray);
            }
            if (o is List <object> list)
            {
                var jsArray = engine.Array.Construct(Array.Empty <JsValue>());
                var args    = new JsValue[1];
                for (var i = 0; i < list.Count; i++)
                {
                    args[0] = TranslateToJs(engine, context, list[i]);
                    engine.Array.PrototypeObject.Push(jsArray, args);
                }
                return(jsArray);
            }
            if (o is List <Document> docList)
            {
                var jsArray = engine.Array.Construct(Array.Empty <JsValue>());
                var args    = new JsValue[1];
                for (var i = 0; i < docList.Count; i++)
                {
                    args[0] = new BlittableObjectInstance(engine, null, Clone(docList[i].Data, context), docList[i].Id, docList[i].LastModified);
                    engine.Array.PrototypeObject.Push(jsArray, args);
                }
                return(jsArray);
            }
            // for admin
            if (o is RavenServer || o is DocumentDatabase)
            {
                AssertAdminScriptInstance();
                return(JsValue.FromObject(engine, o));
            }
            if (o is ObjectInstance j)
            {
                return(j);
            }
            if (o is bool b)
            {
                return(b ? JsBoolean.True : JsBoolean.False);
            }
            if (o is int integer)
            {
                return(integer);
            }
            if (o is double dbl)
            {
                return(dbl);
            }
            if (o is string s)
            {
                return(s);
            }
            if (o is LazyStringValue ls)
            {
                return(ls.ToString());
            }
            if (o is LazyCompressedStringValue lcs)
            {
                return(lcs.ToString());
            }
            if (o is LazyNumberValue lnv)
            {
                return(BlittableObjectInstance.BlittableObjectProperty.GetJSValueForLazyNumber(engine, lnv));
            }
            if (o is JsValue js)
            {
                return(js);
            }
            throw new InvalidOperationException("No idea how to convert " + o + " to JsValue");
        }
 public void ExplodeArgsOn(JsValue self, BlittableObjectInstance args)
 {
     _selfInstance = self;
     _args         = args;
 }
Exemplo n.º 11
0
            private JsValue TranslateToJs(Engine engine, JsonOperationContext context, object o)
            {
                BlittableJsonReaderObject Clone(BlittableJsonReaderObject origin)
                {
                    if (ReadOnly)
                    {
                        return(origin);
                    }

                    // RavenDB-8286
                    // here we need to make sure that we aren't sending a value to
                    // the js engine that might be modified by the actions of the js engine
                    // for example, calling put() mgiht cause the original data to change
                    // because we defrag the data that we looked at. We are handling this by
                    // ensuring that we have our own, safe, copy.
                    var cloned = origin.Clone(context);

                    _disposables.Add(cloned);
                    return(cloned);
                }

                BlittableObjectInstance blittableObjectInstance;

                if (o is Tuple <Document, Lucene.Net.Documents.Document, IState> t)
                {
                    var d = t.Item1;
                    blittableObjectInstance = new BlittableObjectInstance(engine, null, Clone(d.Data), d.Id, d.LastModified, d.ChangeVector)
                    {
                        LuceneDocument = t.Item2,
                        LuceneState    = t.Item3
                    };
                    _objectInstances.Add(blittableObjectInstance);
                    return(blittableObjectInstance);
                }
                if (o is Document doc)
                {
                    blittableObjectInstance = new BlittableObjectInstance(engine, null, Clone(doc.Data), doc.Id, doc.LastModified);
                    _objectInstances.Add(blittableObjectInstance);
                    return(blittableObjectInstance);
                }
                if (o is DocumentConflict dc)
                {
                    blittableObjectInstance = new BlittableObjectInstance(engine, null, Clone(dc.Doc), dc.Id, dc.LastModified);
                    _objectInstances.Add(blittableObjectInstance);
                    return(blittableObjectInstance);
                }

                if (o is BlittableJsonReaderObject json)
                {
                    blittableObjectInstance = new BlittableObjectInstance(engine, null, json, null, null);
                    _objectInstances.Add(blittableObjectInstance);
                    return(blittableObjectInstance);
                }

                if (o == null)
                {
                    return(Undefined.Instance);
                }
                if (o is long lng)
                {
                    return(new JsValue(lng));
                }
                if (o is BlittableJsonReaderArray bjra)
                {
                    var jsArray = ScriptEngine.Array.Construct(Array.Empty <JsValue>());
                    var args    = new JsValue[1];
                    for (var i = 0; i < bjra.Length; i++)
                    {
                        var value = TranslateToJs(ScriptEngine, context, bjra[i]);
                        args[0] = value as JsValue ?? JsValue.FromObject(ScriptEngine, value);
                        ScriptEngine.Array.PrototypeObject.Push(jsArray, args);
                    }
                    return(jsArray);
                }
                if (o is List <object> list)
                {
                    var jsArray = ScriptEngine.Array.Construct(Array.Empty <JsValue>());
                    var args    = new JsValue[1];
                    for (var i = 0; i < list.Count; i++)
                    {
                        var value = TranslateToJs(ScriptEngine, context, list[i]);
                        args[0] = value as JsValue ?? JsValue.FromObject(ScriptEngine, value);
                        ScriptEngine.Array.PrototypeObject.Push(jsArray, args);
                    }
                    return(jsArray);
                }
                // for admin
                if (o is RavenServer || o is DocumentDatabase)
                {
                    AssertAdminScriptInstance();
                    return(JsValue.FromObject(engine, o));
                }
                if (o is ObjectInstance j)
                {
                    return(j);
                }
                if (o is bool b)
                {
                    return(new JsValue(b));
                }
                if (o is int integer)
                {
                    return(new JsValue(integer));
                }
                if (o is double dbl)
                {
                    return(new JsValue(dbl));
                }
                if (o is string s)
                {
                    return(new JsValue(s));
                }
                if (o is LazyStringValue ls)
                {
                    return(new JsValue(ls.ToString()));
                }
                if (o is LazyCompressedStringValue lcs)
                {
                    return(new JsValue(lcs.ToString()));
                }
                if (o is LazyNumberValue lnv)
                {
                    return(new JsValue(lnv.ToString()));
                }
                if (o is JsValue js)
                {
                    return(js);
                }
                throw new InvalidOperationException("No idea how to convert " + o + " to JsValue");
            }
Exemplo n.º 12
0
            private static JsValue ScalarToRawString(JsValue self2, JsValue[] args)
            {
                if (args.Length != 2)
                {
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) may be called on with two parameters only");
                }


                JsValue firstParam = args[0];

                if (firstParam.IsObject() == false || args[0].AsObject() is BlittableObjectInstance == false)
                {
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) may be called with a document first parameter only");
                }

                JsValue secondParam = args[1];

                if (args[1].IsObject() == false || secondParam.AsObject() is FunctionInstance == false)
                {
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) must be called with a second lambda argument");
                }



                BlittableObjectInstance selfInstance = firstParam.AsObject() as BlittableObjectInstance;
                FunctionInstance        lambda       = secondParam.AsObject() as FunctionInstance;
                //TODO: expose this in Jint directly instead of reflection


                var funcDeclField = typeof(ScriptFunctionInstance).GetField("_functionDeclaration", BindingFlags.Instance | BindingFlags.NonPublic);
                var func          = (IFunction)funcDeclField.GetValue(lambda);


                var ret = func.Body.Body.As <ReturnStatement[]>();

                if (ret.Length != 1)
                {
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) lambda to field must contain a single return expression");
                }
                StaticMemberExpression staticMemberExpression = ret[0].Argument.As <StaticMemberExpression>();
                var prop = staticMemberExpression.Property;

                if (staticMemberExpression.Object is Identifier == false)
                {
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) lambda to field must contain a single return expression of a single field");
                }
                var propName = prop.As <Identifier>().Name;

                if (selfInstance.OwnValues.TryGetValue(propName, out var existingValue))
                {
                    if (existingValue.Changed)
                    {
                        return(existingValue.Value);
                    }
                }

                var propertyIndex = selfInstance.Blittable.GetPropertyIndex(propName);

                if (propertyIndex == -1)
                {
                    return(new JsValue(new ObjectInstance(selfInstance.Engine)
                    {
                        Extensible = true
                    }));
                }

                BlittableJsonReaderObject.PropertyDetails propDetails = new BlittableJsonReaderObject.PropertyDetails();
                selfInstance.Blittable.GetPropertyByIndex(propertyIndex, ref propDetails);
                var value = propDetails.Value;

                switch (propDetails.Token & BlittableJsonReaderBase.TypesMask)
                {
                case BlittableJsonToken.Null:
                    return(JsValue.Null);

                case BlittableJsonToken.Boolean:
                    return(new JsValue((bool)propDetails.Value));

                case BlittableJsonToken.Integer:
                    return(new JsValue(new ObjectWrapper(selfInstance.Engine, value)));

                case BlittableJsonToken.LazyNumber:
                    return(new JsValue(new ObjectWrapper(selfInstance.Engine, value)));

                case BlittableJsonToken.String:
                    return(new JsValue(new ObjectWrapper(selfInstance.Engine, value)));

                case BlittableJsonToken.CompressedString:
                    return(new JsValue(new ObjectWrapper(selfInstance.Engine, value)));

                default:
                    throw new InvalidOperationException("scalarToRawString(document, lambdaToField) lambda to field must return either raw numeric or raw string types");
                }
            }