Bug 1663365 - Move ctypes APIs out of jsfriendapi.h into a new js/public/experimental/CTypes.h header. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D95671
This commit is contained in:
Jeff Walden 2020-11-07 00:04:26 +00:00
Родитель b0435c3949
Коммит c25f892c77
6 изменённых файлов: 67 добавлений и 51 удалений

Просмотреть файл

@ -21,6 +21,7 @@
#include <algorithm>
#include "mozilla/ipc/BackgroundChild.h"
#include "GeckoProfiler.h"
#include "js/experimental/CTypes.h" // JS::CTypesActivityType, JS::SetCTypesActivityCallback
#include "jsfriendapi.h"
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/ContextOptions.h"

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#ifndef js_experimental_CTypes_h
#define js_experimental_CTypes_h
#include "mozilla/Attributes.h" // MOZ_RAII
#include "jstypes.h" // JS_FRIEND_API
struct JS_PUBLIC_API JSContext;
namespace JS {
/**
* The type of ctypes activity that is occurring.
*/
enum class CTypesActivityType {
BeginCall,
EndCall,
BeginCallback,
EndCallback,
};
/**
* The signature of a function invoked at the leading or trailing edge of ctypes
* activity.
*/
using CTypesActivityCallback = void (*)(JSContext*, CTypesActivityType);
/**
* Sets a callback that is run whenever js-ctypes is about to be used when
* calling into C.
*/
extern JS_FRIEND_API void SetCTypesActivityCallback(JSContext* cx,
CTypesActivityCallback cb);
class MOZ_RAII JS_FRIEND_API AutoCTypesActivityCallback {
private:
JSContext* cx;
CTypesActivityCallback callback;
CTypesActivityType endType;
public:
AutoCTypesActivityCallback(JSContext* cx, CTypesActivityType beginType,
CTypesActivityType endType);
~AutoCTypesActivityCallback() { DoEndCallback(); }
void DoEndCallback() {
if (callback) {
callback(cx, endType);
callback = nullptr;
}
}
};
} // namespace JS
#endif // js_experimental_CTypes_h

Просмотреть файл

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ctypes/CTypes.h"
#include "js/experimental/CTypes.h" // JS::CTypesActivity{Callback,Type}, JS::SetCTypesActivityCallback
#include "mozilla/CheckedInt.h"
#include "mozilla/FloatingPoint.h"

Просмотреть файл

@ -643,57 +643,6 @@ extern JS_FRIEND_API void PrepareScriptEnvironmentAndInvoke(
JS_FRIEND_API void SetScriptEnvironmentPreparer(
JSContext* cx, ScriptEnvironmentPreparer* preparer);
} // namespace js
namespace JS {
/**
* The type of ctypes activity that is occurring.
*/
enum class CTypesActivityType {
BeginCall,
EndCall,
BeginCallback,
EndCallback,
};
/**
* The signature of a function invoked at the leading or trailing edge of ctypes
* activity.
*/
using CTypesActivityCallback = void (*)(JSContext*, CTypesActivityType);
/**
* Sets a callback that is run whenever js-ctypes is about to be used when
* calling into C.
*/
extern JS_FRIEND_API void SetCTypesActivityCallback(JSContext* cx,
CTypesActivityCallback cb);
class MOZ_RAII JS_FRIEND_API AutoCTypesActivityCallback {
private:
JSContext* cx;
CTypesActivityCallback callback;
CTypesActivityType endType;
public:
AutoCTypesActivityCallback(JSContext* cx, CTypesActivityType beginType,
CTypesActivityType endType);
~AutoCTypesActivityCallback() { DoEndCallback(); }
void DoEndCallback() {
if (callback) {
callback(cx, endType);
callback = nullptr;
}
}
};
} // namespace JS
namespace js {
// Abstract base class for objects that build allocation metadata for JavaScript
// values.
struct AllocationMetadataBuilder {

Просмотреть файл

@ -224,6 +224,7 @@ EXPORTS.js += [
# We expose them as-is, buyer beware.
EXPORTS.js.experimental += [
"../public/experimental/CodeCoverage.h",
"../public/experimental/CTypes.h",
"../public/experimental/Intl.h",
"../public/experimental/JitInfo.h",
"../public/experimental/SourceHook.h",

Просмотреть файл

@ -34,6 +34,7 @@
#include "js/AllocationRecording.h"
#include "js/BuildId.h" // JS::BuildIdOp
#include "js/Debug.h"
#include "js/experimental/CTypes.h" // JS::CTypesActivityCallback
#include "js/experimental/SourceHook.h" // js::SourceHook
#include "js/friend/StackLimits.h" // js::ReportOverRecursed
#include "js/friend/UsageStatistics.h" // JSAccumulateTelemetryDataCallback