diff options
author | Matt Broadstone <mbroadst@mongodb.com> | 2023-01-04 16:01:17 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-04 16:40:22 +0000 |
commit | 2d1d04a9b387538a23de3f78006972992b0258ad (patch) | |
tree | 788eaca256041f158cb0238898654e34a3fe53ce /src/mongo/scripting/mozjs | |
parent | e9c0261130bd3e06ab5d206c6b6632ab96758733 (diff) | |
download | mongo-2d1d04a9b387538a23de3f78006972992b0258ad.tar.gz |
SERVER-72286 Convert all shard split tests to use ES modules
Diffstat (limited to 'src/mongo/scripting/mozjs')
-rw-r--r-- | src/mongo/scripting/mozjs/implscope.cpp | 9 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/implscope.h | 2 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/module_loader.cpp | 14 |
3 files changed, 11 insertions, 14 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp index fa5d95540aa..73c541e6161 100644 --- a/src/mongo/scripting/mozjs/implscope.cpp +++ b/src/mongo/scripting/mozjs/implscope.cpp @@ -665,7 +665,7 @@ void MozJSImplScope::_MozJSCreateFunction(StringData raw, JS::MutableHandleValue bool MozJSImplScope::onSyncPromiseResolved(JSContext* cx, unsigned argc, JS::Value* vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); auto scope = getScope(cx); - scope->_promiseResult.emplace(args[0]); + scope->_promiseResult.emplace(cx, args[0]); args.rval().setUndefined(); return true; } @@ -934,6 +934,10 @@ bool MozJSImplScope::exec(StringData code, JSObject* modulePtr = nullptr; if (shouldTryExecAsModule(_context, name, success)) { + // If we should run this as a module, we need to clear the previous exception in order + // to catch stack traces for future exceptions. + JS_ClearPendingException(_context); + modulePtr = _moduleLoader->loadRootModuleFromSource(_context, name, code); success = modulePtr != nullptr; } @@ -963,6 +967,9 @@ bool MozJSImplScope::exec(StringData code, if (success) { JS::RootedObject evaluationPromise(_context, &out.toObject()); success = JS::ThrowOnModuleEvaluationFailure(_context, evaluationPromise); + if (success) { + success = awaitPromise(_context, evaluationPromise, &out); + } } } } diff --git a/src/mongo/scripting/mozjs/implscope.h b/src/mongo/scripting/mozjs/implscope.h index 1a517b48944..0e0ce3e32cb 100644 --- a/src/mongo/scripting/mozjs/implscope.h +++ b/src/mongo/scripting/mozjs/implscope.h @@ -457,7 +457,7 @@ private: std::unique_ptr<ModuleLoader> _moduleLoader; std::unique_ptr<EnvironmentPreparer> _environmentPreparer; - boost::optional<JS::HandleValue> _promiseResult; + boost::optional<JS::RootedValue> _promiseResult; WrapType<BinDataInfo> _binDataProto; WrapType<BSONInfo> _bsonProto; diff --git a/src/mongo/scripting/mozjs/module_loader.cpp b/src/mongo/scripting/mozjs/module_loader.cpp index 836a1a27892..9341e2c3ce5 100644 --- a/src/mongo/scripting/mozjs/module_loader.cpp +++ b/src/mongo/scripting/mozjs/module_loader.cpp @@ -217,18 +217,8 @@ JSString* ModuleLoader::resolveAndNormalize(JSContext* cx, } boost::system::error_code ec; - auto fullPath = [&]() { - if (!boost::filesystem::is_directory(refAbsPath)) { - return boost::filesystem::canonical(specifierPath, refAbsPath.parent_path(), ec) - .lexically_normal() - .string(); - } - - return boost::filesystem::canonical(specifierPath, refAbsPath, ec) - .lexically_normal() - .string(); - }(); - + auto fullPath = + boost::filesystem::canonical(specifierPath, _baseUrl, ec).lexically_normal().string(); if (ec) { if (ec.value() == boost::system::errc::no_such_file_or_directory) { JS_ReportErrorUTF8(cx, |