Skip to content

Commit

Permalink
Remove jsapi header and feed .cpp into bindgen (servo#486)
Browse files Browse the repository at this point in the history
* Remove jsapi.hpp and feed .cpp into bindgen

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* regen wrappers

apart from resorting, only real change is `MutableHandle<Value>` -> `MutableHandleValue` in FromPropertyDescriptor

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Bump mozjs-sys version

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev authored Jul 29, 2024
1 parent a7cfa6a commit 3720f6d
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 304 deletions.
2 changes: 1 addition & 1 deletion mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mozjs_sys"
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
repository.workspace = true
version = "0.128.0-3"
version = "0.128.0-4"
authors = ["Mozilla"]
links = "mozjs"
build = "build.rs"
Expand Down
10 changes: 3 additions & 7 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ const SM_TARGET_ENV_VARS: &'static [&'static str] = &[
"OBJCOPY",
];

const EXTRA_FILES: &'static [&'static str] = &[
"makefile.cargo",
"src/rustfmt.toml",
"src/jsapi.hpp",
"src/jsapi.cpp",
];
const EXTRA_FILES: &'static [&'static str] =
&["makefile.cargo", "src/rustfmt.toml", "src/jsapi.cpp"];

/// Which version of moztools we expect
#[cfg(windows)]
Expand Down Expand Up @@ -408,7 +404,7 @@ fn build_jsapi_bindings(build_dir: &Path) {

let mut builder = bindgen::builder()
.rust_target(bindgen::RustTarget::Stable_1_59)
.header("./src/jsapi.hpp")
.header("./src/jsapi.cpp")
// Translate every enum with the "rustified enum" strategy. We should
// investigate switching to the "constified module" strategy, which has
// similar ergonomics but avoids some potential Rust UB footguns.
Expand Down
100 changes: 99 additions & 1 deletion mozjs-sys/src/jsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,51 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "jsapi.hpp"
#include "jsapi.h"

#include "js/ArrayBuffer.h"
#include "js/ArrayBufferMaybeShared.h"
#include "js/BigInt.h"
#include "js/BuildId.h"
#include "js/ColumnNumber.h"
#include "js/CompilationAndEvaluation.h"
#include "js/ContextOptions.h"
#include "js/Conversions.h"
#include "js/Date.h"
#include "js/Equality.h"
#include "js/ForOfIterator.h"
#include "js/Id.h"
#include "js/Initialization.h"
#include "js/JSON.h"
#include "js/MemoryMetrics.h"
#include "js/Modules.h"
#include "js/Object.h"
#include "js/Promise.h"
#include "js/PropertySpec.h"
#include "js/Proxy.h"
#include "js/Realm.h"
#include "js/RegExp.h"
#include "js/SavedFrameAPI.h"
#include "js/ScalarType.h"
#include "js/SharedArrayBuffer.h"
#include "js/SourceText.h"
#include "js/Stream.h"
#include "js/String.h"
#include "js/StructuredClone.h"
#include "js/Symbol.h"
#include "js/UniquePtr.h"
#include "js/Utility.h"
#include "js/Warnings.h"
#include "js/WasmModule.h"
#include "js/experimental/JSStencil.h"
#include "js/experimental/JitInfo.h"
#include "js/experimental/TypedData.h"
#include "js/friend/DOMProxy.h"
#include "js/friend/ErrorMessages.h"
#include "js/friend/WindowProxy.h"
#include "js/shadow/Object.h"
#include "js/shadow/Shape.h"
#include "jsfriendapi.h"

namespace glue {

Expand Down Expand Up @@ -70,6 +114,7 @@ JSLinearString* AtomToLinearString(JSAtom* atom) {
}

// Wrappers around UniquePtr functions

/**
* Create a new ArrayBuffer with the given contents. The contents must not be
* modified by any other code, internal or external.
Expand Down Expand Up @@ -292,3 +337,56 @@ void GetExceptionCause(JSObject* exc, JS::MutableHandleValue dest) {
}
}
} // namespace glue

// There's a couple of classes from pre-57 releases of SM that bindgen can't
// deal with. https://github.com/rust-lang-nursery/rust-bindgen/issues/851
// https://bugzilla.mozilla.org/show_bug.cgi?id=1277338
// https://rust-lang-nursery.github.io/rust-bindgen/replacing-types.html

/**
* <div rustbindgen replaces="JS::CallArgs"></div>
*/

class MOZ_STACK_CLASS CallArgsReplacement {
protected:
JS::Value* argv_;
unsigned argc_;
bool constructing_ : 1;
bool ignoresReturnValue_ : 1;
#ifdef JS_DEBUG
JS::detail::IncludeUsedRval wantUsedRval_;
#endif
};

/**
* <div rustbindgen replaces="JSJitMethodCallArgs"></div>
*/

class JSJitMethodCallArgsReplacement {
private:
JS::Value* argv_;
unsigned argc_;
bool constructing_ : 1;
bool ignoresReturnValue_ : 1;
#ifdef JS_DEBUG
JS::detail::NoUsedRval wantUsedRval_;
#endif
};

/// <div rustbindgen replaces="JS::MutableHandleIdVector"></div>
struct MutableHandleIdVector_Simple {
void* ptr;
};
static_assert(sizeof(JS::MutableHandleIdVector) ==
sizeof(MutableHandleIdVector_Simple),
"wrong handle size");

/// <div rustbindgen replaces="JS::HandleObjectVector"></div>
struct HandleObjectVector_Simple {
void* ptr;
};

/// <div rustbindgen replaces="JS::MutableHandleObjectVector"></div>
struct MutableHandleObjectVector_Simple {
void* ptr;
};
198 changes: 0 additions & 198 deletions mozjs-sys/src/jsapi.hpp

This file was deleted.

Loading

0 comments on commit 3720f6d

Please sign in to comment.