MCPcopy Create free account
hub / github.com/RubyLouvre/anu / runInContext

Function runInContext

test/json3.js:29–901  ·  view source on GitHub ↗
(context, exports)

Source from the content-addressed store, hash-verified

27 // Public: Initializes JSON 3 using the given `context` object, attaching the
28 // `stringify` and `parse` functions to the specified `exports` object.
29 function runInContext(context, exports) {
30 context || (context = root.Object());
31 exports || (exports = root.Object());
32
33 // Native constructor aliases.
34 var Number = context.Number || root.Number,
35 String = context.String || root.String,
36 Object = context.Object || root.Object,
37 Date = context.Date || root.Date,
38 SyntaxError = context.SyntaxError || root.SyntaxError,
39 TypeError = context.TypeError || root.TypeError,
40 Math = context.Math || root.Math,
41 nativeJSON = context.JSON || root.JSON;
42
43 // Delegate to the native `stringify` and `parse` implementations.
44 if (typeof nativeJSON == "object" && nativeJSON) {
45 exports.stringify = nativeJSON.stringify;
46 exports.parse = nativeJSON.parse;
47 }
48
49 // Convenience aliases.
50 var objectProto = Object.prototype,
51 getClass = objectProto.toString,
52 isProperty = objectProto.hasOwnProperty,
53 undefined;
54
55 // Internal: Contains `try...catch` logic used by other functions.
56 // This prevents other functions from being deoptimized.
57 function attempt(func, errorFunc) {
58 try {
59 func();
60 } catch (exception) {
61 if (errorFunc) {
62 errorFunc();
63 }
64 }
65 }
66
67 // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
68 var isExtended = new Date(-3509827334573292);
69 attempt(function () {
70 // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
71 // results for certain dates in Opera >= 10.53.
72 isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
73 isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
74 });
75
76 // Internal: Determines whether the native `JSON.stringify` and `parse`
77 // implementations are spec-compliant. Based on work by Ken Snyder.
78 function has(name) {
79 if (has[name] != null) {
80 // Return cached feature test result.
81 return has[name];
82 }
83 var isSupported;
84 if (name == "bug-string-char-index") {
85 // IE <= 7 doesn't support accessing string characters using square
86 // bracket notation. IE 8 only supports this for primitives.

Callers 1

json3.jsFile · 0.85

Calls 7

attemptFunction · 0.85
serializeFunction · 0.85
lexFunction · 0.85
abortFunction · 0.85
walkFunction · 0.85
hasFunction · 0.70
getFunction · 0.70

Tested by

no test coverage detected