summaryrefslogtreecommitdiff
path: root/jstests/core/where5.js
blob: d7140cd21f613e113b1c452cd6f28861c76d91ec (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
// Tests toString() on _v8_function in object constructor.
// Verifies that native functions do not expose the _native_function and _native_data properties.

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;
    }

    // This used to crash.
    doc._id.constructor._v8_function.toString();

    // 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);