Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/json/evaljsonprocessor.js
2868 views
1
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
16
/**
17
* @fileoverview Defines a class for parsing JSON using eval.
18
*/
19
20
goog.provide('goog.json.EvalJsonProcessor');
21
22
goog.require('goog.json');
23
goog.require('goog.json.Processor');
24
goog.require('goog.json.Serializer');
25
26
27
28
/**
29
* A class that parses and stringifies JSON using eval (as implemented in
30
* goog.json).
31
* Adapts {@code goog.json} to the {@code goog.json.Processor} interface.
32
*
33
* @param {?goog.json.Replacer=} opt_replacer An optional replacer to use during
34
* serialization.
35
* @param {?boolean=} opt_useUnsafeParsing Whether to use goog.json.unsafeParse
36
* for parsing. Safe parsing is very slow on large strings. On the other
37
* hand, unsafe parsing uses eval() without checking whether the string is
38
* valid, so it should only be used if you trust the source of the string.
39
* @constructor
40
* @implements {goog.json.Processor}
41
* @final
42
* @deprecated Use goog.json.NativeJsonProcessor.
43
*/
44
goog.json.EvalJsonProcessor = function(opt_replacer, opt_useUnsafeParsing) {
45
/**
46
* @type {goog.json.Serializer}
47
* @private
48
*/
49
this.serializer_ = new goog.json.Serializer(opt_replacer);
50
51
/**
52
* @type {function(string): *}
53
* @private
54
*/
55
this.parser_ = opt_useUnsafeParsing ? goog.json.unsafeParse : goog.json.parse;
56
};
57
58
59
/** @override */
60
goog.json.EvalJsonProcessor.prototype.stringify = function(object) {
61
return this.serializer_.serialize(object);
62
};
63
64
65
/** @override */
66
goog.json.EvalJsonProcessor.prototype.parse = function(s) {
67
return this.parser_(s);
68
};
69
70