Bug 1484421 - Move JSON-related functionality into js/public/JSON.h that isn't #include'd in jsapi.h. r=jandem

This commit is contained in:
Jeff Walden 2018-08-20 07:54:45 -07:00
Родитель ffd93ba761
Коммит e4f79e2a19
18 изменённых файлов: 107 добавлений и 55 удалений

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

@ -18,6 +18,7 @@
#include "nsStreamUtils.h"
#include "nsStringStream.h"
#include "js/JSON.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Exceptions.h"
#include "mozilla/dom/FetchUtil.h"

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

@ -20,6 +20,7 @@
#include "imgRequestProxy.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/JSON.h"
#include "js/Value.h"
#include "Layers.h"
#include "nsAppRunner.h"

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

@ -29,6 +29,7 @@
#include "nsIProtocolHandler.h"
#include "nsIScriptSecurityManager.h"
#include "xpcpublic.h"
#include "js/JSON.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/Preferences.h"

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

@ -12,6 +12,7 @@
#include "AccessCheck.h"
#include "jsapi.h"
#include "js/JSON.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/CORSMode.h"

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

@ -17,6 +17,7 @@
#include "mozilla/UseCounter.h"
#include "AccessCheck.h"
#include "js/JSON.h"
#include "js/StableStringChars.h"
#include "jsfriendapi.h"
#include "nsContentCreatorFunctions.h"

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

@ -15,6 +15,7 @@
#include "Layers.h"
#include "ContentChild.h"
#include "TabParent.h"
#include "js/JSON.h"
#include "mozilla/Preferences.h"
#include "mozilla/BrowserElementParent.h"
#include "mozilla/ClearOnShutdown.h"

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

@ -4,6 +4,7 @@
* 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 "js/JSON.h"
#include "nsArrayUtils.h"
#include "PaymentRequestUtils.h"
#include "nsIMutableArray.h"

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

@ -74,6 +74,7 @@
#include "nsStringBuffer.h"
#include "nsIFileChannel.h"
#include "mozilla/Telemetry.h"
#include "js/JSON.h"
#include "jsfriendapi.h"
#include "GeckoProfiler.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"

91
js/public/JSON.h Normal file
Просмотреть файл

@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
/*
* JSON serialization and deserialization operations.
*/
#ifndef js_JSON_h
#define js_JSON_h
#include <stdint.h> // uint32_t
#include "jstypes.h" // JS_PUBLIC_API
#include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle
struct JSContext;
class JSObject;
class JSString;
namespace JS { union Value; }
using JSONWriteCallback = bool (*)(const char16_t* buf, uint32_t len, void* data);
/**
* Performs the JSON.stringify operation, as specified by ECMAScript, except
* writing stringified data by repeated calls of |callback|, with each such
* call passed |data| as argument.
*/
extern JS_PUBLIC_API(bool)
JS_Stringify(JSContext* cx, JS::MutableHandle<JS::Value> value, JS::Handle<JSObject*> replacer,
JS::Handle<JS::Value> space, JSONWriteCallback callback, void* data);
namespace JS {
/**
* An API akin to JS_Stringify but with the goal of not having observable
* side-effects when the stringification is performed. This means it does not
* allow a replacer or a custom space and has the following constraints on its
* input:
*
* 1) The input must be a plain object or array, not an abitrary value.
* 2) Every value in the graph reached by the algorithm starting with this
* object must be one of the following: null, undefined, a string (NOT a
* string object!), a boolean, a finite number (i.e. no NaN or Infinity or
* -Infinity), a plain object with no accessor properties, or an Array with
* no holes.
*
* The actual behavior differs from JS_Stringify only in asserting the above and
* NOT attempting to get the "toJSON" property from things, since that could
* clearly have side-effects.
*/
extern JS_PUBLIC_API(bool)
ToJSONMaybeSafely(JSContext* cx, JS::Handle<JSObject*> input,
JSONWriteCallback callback, void* data);
} /* namespace JS */
/**
* Performs the JSON.parse operation as specified by ECMAScript.
*/
extern JS_PUBLIC_API(bool)
JS_ParseJSON(JSContext* cx, const char16_t* chars, uint32_t len, JS::MutableHandle<JS::Value> vp);
/**
* Performs the JSON.parse operation as specified by ECMAScript.
*/
extern JS_PUBLIC_API(bool)
JS_ParseJSON(JSContext* cx, JS::Handle<JSString*> str, JS::MutableHandle<JS::Value> vp);
/**
* Performs the JSON.parse operation as specified by ECMAScript, using the
* given |reviver| argument as the corresponding optional argument to that
* function.
*/
extern JS_PUBLIC_API(bool)
JS_ParseJSONWithReviver(JSContext* cx, const char16_t* chars, uint32_t len,
JS::Handle<JS::Value> reviver, JS::MutableHandle<JS::Value> vp);
/**
* Performs the JSON.parse operation as specified by ECMAScript, using the
* given |reviver| argument as the corresponding optional argument to that
* function.
*/
extern JS_PUBLIC_API(bool)
JS_ParseJSONWithReviver(JSContext* cx, JS::Handle<JSString*> str, JS::Handle<JS::Value> reviver,
JS::MutableHandle<JS::Value> vp);
#endif /* js_JSON_h */

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

@ -10,6 +10,7 @@
#include "builtin/String.h"
#include "js/JSON.h"
#include "js/Printf.h"
#include "jsapi-tests/tests.h"

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

@ -60,6 +60,7 @@
#include "js/Conversions.h"
#include "js/Date.h"
#include "js/Initialization.h"
#include "js/JSON.h"
#include "js/Proxy.h"
#include "js/SliceBudget.h"
#include "js/StableStringChars.h"

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

@ -4723,61 +4723,6 @@ PropertySpecNameToPermanentId(JSContext* cx, const char* name, jsid* idp);
} /* namespace JS */
/************************************************************************/
/*
* JSON functions
*/
typedef bool (* JSONWriteCallback)(const char16_t* buf, uint32_t len, void* data);
/**
* JSON.stringify as specified by ES5.
*/
JS_PUBLIC_API(bool)
JS_Stringify(JSContext* cx, JS::MutableHandleValue value, JS::HandleObject replacer,
JS::HandleValue space, JSONWriteCallback callback, void* data);
namespace JS {
/**
* An API akin to JS_Stringify but with the goal of not having observable
* side-effects when the stringification is performed. This means it does not
* allow a replacer or a custom space, and has the following constraints on its
* input:
*
* 1) The input must be a plain object or array, not an abitrary value.
* 2) Every value in the graph reached by the algorithm starting with this
* object must be one of the following: null, undefined, a string (NOT a
* string object!), a boolean, a finite number (i.e. no NaN or Infinity or
* -Infinity), a plain object with no accessor properties, or an Array with
* no holes.
*
* The actual behavior differs from JS_Stringify only in asserting the above and
* NOT attempting to get the "toJSON" property from things, since that could
* clearly have side-effects.
*/
JS_PUBLIC_API(bool)
ToJSONMaybeSafely(JSContext* cx, JS::HandleObject input,
JSONWriteCallback callback, void* data);
} /* namespace JS */
/**
* JSON.parse as specified by ES5.
*/
JS_PUBLIC_API(bool)
JS_ParseJSON(JSContext* cx, const char16_t* chars, uint32_t len, JS::MutableHandleValue vp);
JS_PUBLIC_API(bool)
JS_ParseJSON(JSContext* cx, JS::HandleString str, JS::MutableHandleValue vp);
JS_PUBLIC_API(bool)
JS_ParseJSONWithReviver(JSContext* cx, const char16_t* chars, uint32_t len, JS::HandleValue reviver,
JS::MutableHandleValue vp);
JS_PUBLIC_API(bool)
JS_ParseJSONWithReviver(JSContext* cx, JS::HandleString str, JS::HandleValue reviver,
JS::MutableHandleValue vp);
/************************************************************************/
/**

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

@ -143,6 +143,7 @@ EXPORTS.js += [
'../public/HeapAPI.h',
'../public/Id.h',
'../public/Initialization.h',
'../public/JSON.h',
'../public/MemoryFunctions.h',
'../public/MemoryMetrics.h',
'../public/Principals.h',

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

@ -81,6 +81,7 @@
#include "js/Debug.h"
#include "js/GCVector.h"
#include "js/Initialization.h"
#include "js/JSON.h"
#include "js/Printf.h"
#include "js/StableStringChars.h"
#include "js/StructuredClone.h"

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

@ -7,6 +7,7 @@
#include "TelemetryGeckoViewPersistence.h"
#include "jsapi.h"
#include "js/JSON.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/JSONWriter.h"
#include "mozilla/Path.h"

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

@ -8,6 +8,7 @@
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/JSON.h"
#include "js/TracingAPI.h"
#include "xpcpublic.h"

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

@ -7,6 +7,7 @@
#include "JSControl.h"
#include "js/Conversions.h"
#include "js/JSON.h"
#include "ChildInternal.h"
#include "ParentInternal.h"
#include "xpcprivate.h"

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

@ -19,6 +19,7 @@
#include "nsIWebNavigation.h"
#include "nsIInterfaceRequestorUtils.h"
#include "shared-libraries.h"
#include "js/JSON.h"
#include "js/Value.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Promise.h"