Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions packages/async-rewriter2/src/stages/transform-maybe-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,8 @@ export default ({ types: t }: { types: typeof BabelTypes }): babel.PluginObj<{ f
// of helpers which are available inside the function.
const identifierGroupKey = '@@mongosh.identifierGroup';

// We fetch the symbol constructor as
// Object.getOwnPropertySymbols(Array.prototype)[0].constructor
// because Symbol refers to BSONSymbol inside the target mongosh context.
// (This is the only mongosh-specific hack in here.)
const symbolConstructor = babel.template.expression(`
Object.getOwnPropertySymbols(Array.prototype)[0].constructor
`)();

const syntheticPromiseSymbolTemplate = babel.template.statement(`
const SP_IDENTIFIER = SYMBOL_CONSTRUCTOR.for("@@mongosh.syntheticPromise");
const SP_IDENTIFIER = Symbol.for("@@mongosh.syntheticPromise");
`);

const markSyntheticPromiseTemplate = babel.template.statement(`
Expand Down Expand Up @@ -224,8 +216,7 @@ export default ({ types: t }: { types: typeof BabelTypes }): babel.PluginObj<{ f
const commonHelpers = existingIdentifiers ? [] : [
Object.assign(
syntheticPromiseSymbolTemplate({
SP_IDENTIFIER: syntheticPromiseSymbol,
SYMBOL_CONSTRUCTOR: symbolConstructor
SP_IDENTIFIER: syntheticPromiseSymbol
}),
{ [isGeneratedHelper]: true }
),
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-repl/test/e2e-bson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('BSON e2e', function() {
NumberInt: NumberInt("32"),
NumberLong: NumberLong("64"),
Timestamp: new Timestamp(1, 100),
Symbol: new Symbol('abc'),
Symbol: new BSONSymbol('abc'),
Code: new Code('abc'),
NumberDecimal: NumberDecimal('1'),
BinData: BinData(128, 'MTIzNA=='),
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('BSON e2e', function() {
shell.assertNoErrors();
});
it('Symbol prints when created by user', async() => {
const value = 'new Symbol("symbol")';
const value = 'new BSONSymbol("symbol")';
await shell.writeInputLine(value);
await eventually(() => {
shell.assertContainsOutput('"symbol"');
Expand Down Expand Up @@ -504,7 +504,7 @@ describe('BSON e2e', function() {
shell.assertNoErrors();
});
it('Symbol has help when created by user', async() => {
const value = 'new Symbol("1")';
const value = 'new BSONSymbol("1")';
await shell.writeInputLine(`${value}.help`);
await eventually(() => {
shell.assertContainsOutput('BSON Class');
Expand Down
8 changes: 0 additions & 8 deletions packages/i18n/src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1752,14 +1752,6 @@ const translations: Catalog = {
},
attributes: {}
},
Symbol: {
help: {
description: 'The Symbol BSON Class helper method that constructs a BSONSymbol type. Deprecated since server version 1.6',
link: 'https://mongodb.github.io/node-mongodb-native/3.6/api/Symbol.html',
example: 'Symbol("abc")'
},
attributes: {}
},
BSONSymbol: {
help: {
description: 'The Symbol BSON Class. Deprecated since server version 1.6',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ internal class MongoShellEvaluator(client: MongoClient, private val context: Mon
shellEvaluator = global.getMember("ShellEvaluator").newInstance(shellInternalState, resultHandler())
toShellResultFn = global.getMember("toShellResult")
getShellApiTypeFn = global.getMember("getShellApiType")
val jsSymbol = context.bindings["Symbol"]!!
shellInternalState.invokeMember("setCtx", context.bindings)
initContext(context.bindings, jsSymbol)
initContext(context.bindings)
}

private fun resultHandler() = context.jsFun { args ->
Expand All @@ -47,9 +46,7 @@ internal class MongoShellEvaluator(client: MongoClient, private val context: Mon
}
}

private fun initContext(bindings: Value, jsSymbol: Value) {
bindings["BSONSymbol"] = bindings["Symbol"]
bindings["Symbol"] = jsSymbol
private fun initContext(bindings: Value) {
val date = context.eval("(dateHelper) => function inner() { return dateHelper(new.target !== undefined, ...arguments) }", "dateHelper_script")
.execute(ProxyExecutable { args -> dateHelper(args[0].asBoolean(), args.drop(1)) })
date["now"] = ProxyExecutable { System.currentTimeMillis() }
Expand Down
12 changes: 4 additions & 8 deletions packages/shell-api/src/shell-bson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,22 @@ describe('Shell BSON', () => {
expect.fail('Expecting error, nothing thrown');
});
});
describe('Symbol', () => {
describe('BSONSymbol', () => {
it('without new', () => {
const s = shellBson.Symbol('5ebbe8e2905bb493d6981b6b');
const s = shellBson.BSONSymbol('5ebbe8e2905bb493d6981b6b');
expect(s._bsontype).to.equal('Symbol');
expect(s.toString()).to.equal('5ebbe8e2905bb493d6981b6b');
});
it('with new', () => {
const s = new (shellBson.Symbol as any)('5ebbe8e2905bb493d6981b6b');
const s = new (shellBson.BSONSymbol as any)('5ebbe8e2905bb493d6981b6b');
expect(s._bsontype).to.equal('Symbol');
expect(s.toString()).to.equal('5ebbe8e2905bb493d6981b6b');
});
it('has help and other metadata', async() => {
const s = shellBson.Symbol('5ebbe8e2905bb493d6981b6b');
const s = shellBson.BSONSymbol('5ebbe8e2905bb493d6981b6b');
expect((await toShellResult(s.help)).type).to.equal('Help');
expect((await toShellResult(s.help())).type).to.equal('Help');
});
it('constructs with default args 1', () => {
const s = shellBson.Symbol();
expect(s.toString()).to.equal('');
});
});
describe('Timestamp', () => {
it('without new', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/shell-api/src/shell-bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export default function constructShellBson(bson: typeof BSON, printWarning: (msg
assertArgsDefinedType([id], [[undefined, 'string']], 'ObjectId');
return new bson.ObjectId(id);
}, { prototype: bson.ObjectId.prototype }),
Symbol: Object.assign(function(value = ''): any {
return new bson.BSONSymbol(value);
}, { prototype: bson.BSONSymbol.prototype }),
Timestamp: Object.assign(function(low = 0, high = 0): any {
assertArgsDefinedType([low, high], ['number', 'number'], 'Timestamp');
return new bson.Timestamp(low, high);
Expand Down