summaryrefslogtreecommitdiff
path: root/jstests/core/where5.js
blob: 02530dbd71ed010f7ccffc7b81ce5c1b2a790c7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Tests toString() in object constructor.
// Verifies that native functions do not expose the _native_function and _native_data properties.
// @tags: [
//     # Uses $where operator
//     requires_scripting
// ]

var t = db.where5;

t.drop();

t.save({a: 1});

// Prints information on the document's _id field.
function printIdConstructor(doc) {
    // If doc is undefined, this function is running inside server.
    if (!doc) {
        doc = this;
    }

    // Verify that function and data fields are hidden.
    assert(!('_native_function' in sleep));
    assert(!('_native_data' in sleep));

    // Predicate for matching document in collection.
    return true;
}

print('Running JS function in server...');
assert.eq(t.find({$where: printIdConstructor}).itcount(), 1);

print('Running JS function in client...');
var doc = t.findOne();
printIdConstructor(doc);