Bug 1559275 - Avoid OwningCompileOptions accessors in js-rust glue. r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Wed, 19 Jun 2019 00:50:43 +0000
changeset 479167 cd6b4126a1b63d23ebd7a42ff69434cfef655314
parent 479166 3c83d9936c2c2b2ecaf2944db29f2ecb56950cf3
child 479168 96acb8c9df07284e4df2af13f5b23ebfd90f8e31
push id36172
push userrgurzau@mozilla.com
push dateWed, 19 Jun 2019 09:55:37 +0000
treeherdermozilla-central@8bce401b8833 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1559275
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559275 - Avoid OwningCompileOptions accessors in js-rust glue. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D35260
js/rust/src/jsglue.cpp
--- a/js/rust/src/jsglue.cpp
+++ b/js/rust/src/jsglue.cpp
@@ -415,25 +415,36 @@ const void* CreateWrapperProxyHandler(co
 const void* GetCrossCompartmentWrapper() {
   return &js::CrossCompartmentWrapper::singleton;
 }
 
 const void* GetSecurityWrapper() {
   return &js::CrossCompartmentSecurityWrapper::singleton;
 }
 
+void DeleteCompileOptions(JS::ReadOnlyCompileOptions* aOpts) {
+  delete static_cast<JS::OwningCompileOptions*>(aOpts);
+}
+
 JS::ReadOnlyCompileOptions* NewCompileOptions(JSContext* aCx, const char* aFile,
                                               unsigned aLine) {
-  JS::OwningCompileOptions* opts = new JS::OwningCompileOptions(aCx);
-  opts->setFileAndLine(aCx, aFile, aLine);
-  return opts;
-}
+  JS::CompileOptions opts(aCx);
+  opts.setFileAndLine(aFile, aLine);
 
-void DeleteCompileOptions(JS::ReadOnlyCompileOptions* aOpts) {
-  delete static_cast<JS::OwningCompileOptions*>(aOpts);
+  JS::OwningCompileOptions* owned = new JS::OwningCompileOptions(aCx);
+  if (!owned) {
+    return nullptr;
+  }
+
+  if (!owned->copy(aCx, opts)) {
+    DeleteCompileOptions(owned);
+    return nullptr;
+  }
+
+  return owned;
 }
 
 JSObject* NewProxyObject(JSContext* aCx, const void* aHandler,
                          JS::HandleValue aPriv, JSObject* proto,
                          JSObject* parent, JSObject* call,
                          JSObject* construct) {
   js::ProxyOptions options;
   return js::NewProxyObject(aCx, (js::BaseProxyHandler*)aHandler, aPriv, proto,