Path: blob/trunk/third_party/closure/goog/json/evaljsonprocessor.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.131415/**16* @fileoverview Defines a class for parsing JSON using eval.17*/1819goog.provide('goog.json.EvalJsonProcessor');2021goog.require('goog.json');22goog.require('goog.json.Processor');23goog.require('goog.json.Serializer');24252627/**28* A class that parses and stringifies JSON using eval (as implemented in29* goog.json).30* Adapts {@code goog.json} to the {@code goog.json.Processor} interface.31*32* @param {?goog.json.Replacer=} opt_replacer An optional replacer to use during33* serialization.34* @param {?boolean=} opt_useUnsafeParsing Whether to use goog.json.unsafeParse35* for parsing. Safe parsing is very slow on large strings. On the other36* hand, unsafe parsing uses eval() without checking whether the string is37* valid, so it should only be used if you trust the source of the string.38* @constructor39* @implements {goog.json.Processor}40* @final41* @deprecated Use goog.json.NativeJsonProcessor.42*/43goog.json.EvalJsonProcessor = function(opt_replacer, opt_useUnsafeParsing) {44/**45* @type {goog.json.Serializer}46* @private47*/48this.serializer_ = new goog.json.Serializer(opt_replacer);4950/**51* @type {function(string): *}52* @private53*/54this.parser_ = opt_useUnsafeParsing ? goog.json.unsafeParse : goog.json.parse;55};565758/** @override */59goog.json.EvalJsonProcessor.prototype.stringify = function(object) {60return this.serializer_.serialize(object);61};626364/** @override */65goog.json.EvalJsonProcessor.prototype.parse = function(s) {66return this.parser_(s);67};686970