~ubuntu-branches/ubuntu/trusty/nodejs/trusty

« back to all changes in this revision

Viewing changes to deps/v8/src/d8.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 
 
28
"use strict";
 
29
 
28
30
String.prototype.startsWith = function (str) {
29
 
  if (str.length > this.length)
 
31
  if (str.length > this.length) {
30
32
    return false;
 
33
  }
31
34
  return this.substr(0, str.length) == str;
32
 
}
 
35
};
33
36
 
34
37
function log10(num) {
35
38
  return Math.log(num)/Math.log(10);
52
55
  for (var i = 0; i < parts.length; i++) {
53
56
    var part = parts[i];
54
57
    var next = current[part];
55
 
    if (!next)
 
58
    if (!next) {
56
59
      return [];
 
60
    }
57
61
    current = next;
58
62
  }
59
63
  var result = [];
63
67
    var properties = mirror.properties();
64
68
    for (var i = 0; i < properties.length; i++) {
65
69
      var name = properties[i].name();
66
 
      if (typeof name === 'string' && name.startsWith(last))
 
70
      if (typeof name === 'string' && name.startsWith(last)) {
67
71
        result.push(name);
 
72
      }
68
73
    }
69
74
    current = ToInspectableObject(current.__proto__);
70
75
  }
73
78
 
74
79
 
75
80
// Global object holding debugger related constants and state.
76
 
const Debug = {};
 
81
var Debug = {};
77
82
 
78
83
 
79
84
// Debug events which can occour in the V8 JavaScript engine. These originate
108
113
 
109
114
 
110
115
// Current debug state.
111
 
const kNoFrame = -1;
 
116
var kNoFrame = -1;
112
117
Debug.State = {
113
118
  currentFrame: kNoFrame,
114
119
  displaySourceStartLine: -1,
115
120
  displaySourceEndLine: -1,
116
121
  currentSourceLine: -1
117
 
}
 
122
};
118
123
var trace_compile = false;  // Tracing all compile events?
119
124
var trace_debug_json = false; // Tracing all debug json packets?
120
 
var last_cmd_line = '';
 
125
var last_cmd = '';
121
126
//var lol_is_enabled;  // Set to true in d8.cc if LIVE_OBJECT_LIST is defined.
122
127
var lol_next_dump_index = 0;
123
 
const kDefaultLolLinesToPrintAtATime = 10;
124
 
const kMaxLolLinesToPrintAtATime = 1000;
 
128
var kDefaultLolLinesToPrintAtATime = 10;
 
129
var kMaxLolLinesToPrintAtATime = 1000;
125
130
var repeat_cmd_line = '';
126
131
var is_running = true;
 
132
// Global variable used to store whether a handle was requested.
 
133
var lookup_handle = null;
127
134
 
128
135
// Copied from debug-delay.js.  This is needed below:
129
136
function ScriptTypeFlag(type) {
150
157
}
151
158
 
152
159
function DebugEventDetails(response) {
153
 
  details = {text:'', running:false}
 
160
  var details = {text:'', running:false};
154
161
 
155
162
  // Get the running state.
156
163
  details.running = response.running();
217
224
 
218
225
    case 'afterCompile':
219
226
      if (trace_compile) {
220
 
        result = 'Source ' + body.script.name + ' compiled:\n'
 
227
        result = 'Source ' + body.script.name + ' compiled:\n';
221
228
        var source = body.script.source;
222
229
        if (!(source[source.length - 1] == '\n')) {
223
230
          result += source;
237
244
  }
238
245
 
239
246
  return details;
240
 
};
 
247
}
241
248
 
242
249
 
243
250
function SourceInfo(body) {
279
286
 
280
287
  // Return the source line text with the underline beneath.
281
288
  return source_text + '\n' + underline;
282
 
};
 
289
}
283
290
 
284
291
 
285
292
// Converts a text command to a JSON request.
289
296
    print("sending: '" + result + "'");
290
297
  }
291
298
  return result;
292
 
};
 
299
}
293
300
 
294
301
 
295
302
function DebugRequest(cmd_line) {
514
521
 
515
522
DebugRequest.prototype.JSONRequest = function() {
516
523
  return this.request_;
517
 
}
 
524
};
518
525
 
519
526
 
520
527
function RequestPacket(command) {
536
543
    json += ',"arguments":';
537
544
    // Encode the arguments part.
538
545
    if (this.arguments.toJSONProtocol) {
539
 
      json += this.arguments.toJSONProtocol()
 
546
      json += this.arguments.toJSONProtocol();
540
547
    } else {
541
548
      json += SimpleObjectToJSON_(this.arguments);
542
549
    }
543
550
  }
544
551
  json += '}';
545
552
  return json;
546
 
}
 
553
};
547
554
 
548
555
 
549
556
DebugRequest.prototype.createRequest = function(command) {
583
590
 
584
591
// Create a JSON request for the evaluation command.
585
592
DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) {
586
 
  // Global varaible used to store whether a handle was requested.
587
593
  lookup_handle = null;
588
594
 
589
595
  if (lol_is_enabled) {
1310
1316
  }
1311
1317
 
1312
1318
  return request;
1313
 
}
 
1319
};
1314
1320
 
1315
1321
 
1316
1322
function extractObjId(args) {
1499
1505
  } else {
1500
1506
    throw new Error('Invalid trace arguments.');
1501
1507
  }
1502
 
}
 
1508
};
1503
1509
 
1504
1510
// Handle the help command.
1505
1511
DebugRequest.prototype.helpCommand_ = function(args) {
1608
1614
  print('');
1609
1615
  print('disconnect|exit|quit       - disconnects and quits the debugger');
1610
1616
  print('help                       - prints this help information');
1611
 
}
 
1617
};
1612
1618
 
1613
1619
 
1614
1620
function formatHandleReference_(value) {
1623
1629
function formatObject_(value, include_properties) {
1624
1630
  var result = '';
1625
1631
  result += formatHandleReference_(value);
1626
 
  result += ', type: object'
 
1632
  result += ', type: object';
1627
1633
  result += ', constructor ';
1628
1634
  var ctor = value.constructorFunctionValue();
1629
1635
  result += formatHandleReference_(ctor);
1943
1949
 
1944
1950
// Convert a JSON response to text for display in a text based debugger.
1945
1951
function DebugResponseDetails(response) {
1946
 
  details = {text:'', running:false}
 
1952
  var details = { text: '', running: false };
1947
1953
 
1948
1954
  try {
1949
1955
    if (!response.success()) {
2168
2174
          }
2169
2175
 
2170
2176
          var current_line = from_line + num;
2171
 
          spacer = maxdigits - (1 + Math.floor(log10(current_line)));
 
2177
          var spacer = maxdigits - (1 + Math.floor(log10(current_line)));
2172
2178
          if (current_line == Debug.State.currentSourceLine + 1) {
2173
2179
            for (var i = 0; i < maxdigits; i++) {
2174
2180
              result += '>';
2308
2314
  }
2309
2315
 
2310
2316
  return details;
2311
 
};
 
2317
}
2312
2318
 
2313
2319
 
2314
2320
/**
2334
2340
 */
2335
2341
ProtocolPackage.prototype.type = function() {
2336
2342
  return this.packet_.type;
2337
 
}
 
2343
};
2338
2344
 
2339
2345
 
2340
2346
/**
2343
2349
 */
2344
2350
ProtocolPackage.prototype.event = function() {
2345
2351
  return this.packet_.event;
2346
 
}
 
2352
};
2347
2353
 
2348
2354
 
2349
2355
/**
2352
2358
 */
2353
2359
ProtocolPackage.prototype.requestSeq = function() {
2354
2360
  return this.packet_.request_seq;
2355
 
}
 
2361
};
2356
2362
 
2357
2363
 
2358
2364
/**
2361
2367
 */
2362
2368
ProtocolPackage.prototype.running = function() {
2363
2369
  return this.packet_.running ? true : false;
2364
 
}
 
2370
};
2365
2371
 
2366
2372
 
2367
2373
ProtocolPackage.prototype.success = function() {
2368
2374
  return this.packet_.success ? true : false;
2369
 
}
 
2375
};
2370
2376
 
2371
2377
 
2372
2378
ProtocolPackage.prototype.message = function() {
2373
2379
  return this.packet_.message;
2374
 
}
 
2380
};
2375
2381
 
2376
2382
 
2377
2383
ProtocolPackage.prototype.command = function() {
2378
2384
  return this.packet_.command;
2379
 
}
 
2385
};
2380
2386
 
2381
2387
 
2382
2388
ProtocolPackage.prototype.body = function() {
2383
2389
  return this.packet_.body;
2384
 
}
 
2390
};
2385
2391
 
2386
2392
 
2387
2393
ProtocolPackage.prototype.bodyValue = function(index) {
2390
2396
  } else {
2391
2397
    return new ProtocolValue(this.packet_.body, this);
2392
2398
  }
2393
 
}
 
2399
};
2394
2400
 
2395
2401
 
2396
2402
ProtocolPackage.prototype.body = function() {
2397
2403
  return this.packet_.body;
2398
 
}
 
2404
};
2399
2405
 
2400
2406
 
2401
2407
ProtocolPackage.prototype.lookup = function(handle) {
2405
2411
  } else {
2406
2412
    return new ProtocolReference(handle);
2407
2413
  }
2408
 
}
 
2414
};
2409
2415
 
2410
2416
 
2411
2417
ProtocolPackage.prototype.raw_json = function() {
2412
2418
  return this.raw_json_;
2413
 
}
 
2419
};
2414
2420
 
2415
2421
 
2416
2422
function ProtocolValue(value, packet) {
2425
2431
 */
2426
2432
ProtocolValue.prototype.type = function() {
2427
2433
  return this.value_.type;
2428
 
}
 
2434
};
2429
2435
 
2430
2436
 
2431
2437
/**
2434
2440
 */
2435
2441
ProtocolValue.prototype.field = function(name) {
2436
2442
  return this.value_[name];
2437
 
}
 
2443
};
2438
2444
 
2439
2445
 
2440
2446
/**
2444
2450
ProtocolValue.prototype.isPrimitive = function() {
2445
2451
  return this.isUndefined() || this.isNull() || this.isBoolean() ||
2446
2452
         this.isNumber() || this.isString();
2447
 
}
 
2453
};
2448
2454
 
2449
2455
 
2450
2456
/**
2453
2459
 */
2454
2460
ProtocolValue.prototype.handle = function() {
2455
2461
  return this.value_.handle;
2456
 
}
 
2462
};
2457
2463
 
2458
2464
 
2459
2465
/**
2462
2468
 */
2463
2469
ProtocolValue.prototype.isUndefined = function() {
2464
2470
  return this.value_.type == 'undefined';
2465
 
}
 
2471
};
2466
2472
 
2467
2473
 
2468
2474
/**
2471
2477
 */
2472
2478
ProtocolValue.prototype.isNull = function() {
2473
2479
  return this.value_.type == 'null';
2474
 
}
 
2480
};
2475
2481
 
2476
2482
 
2477
2483
/**
2480
2486
 */
2481
2487
ProtocolValue.prototype.isBoolean = function() {
2482
2488
  return this.value_.type == 'boolean';
2483
 
}
 
2489
};
2484
2490
 
2485
2491
 
2486
2492
/**
2489
2495
 */
2490
2496
ProtocolValue.prototype.isNumber = function() {
2491
2497
  return this.value_.type == 'number';
2492
 
}
 
2498
};
2493
2499
 
2494
2500
 
2495
2501
/**
2498
2504
 */
2499
2505
ProtocolValue.prototype.isString = function() {
2500
2506
  return this.value_.type == 'string';
2501
 
}
 
2507
};
2502
2508
 
2503
2509
 
2504
2510
/**
2508
2514
ProtocolValue.prototype.isObject = function() {
2509
2515
  return this.value_.type == 'object' || this.value_.type == 'function' ||
2510
2516
         this.value_.type == 'error' || this.value_.type == 'regexp';
2511
 
}
 
2517
};
2512
2518
 
2513
2519
 
2514
2520
/**
2518
2524
ProtocolValue.prototype.constructorFunctionValue = function() {
2519
2525
  var ctor = this.value_.constructorFunction;
2520
2526
  return this.packet_.lookup(ctor.ref);
2521
 
}
 
2527
};
2522
2528
 
2523
2529
 
2524
2530
/**
2528
2534
ProtocolValue.prototype.protoObjectValue = function() {
2529
2535
  var proto = this.value_.protoObject;
2530
2536
  return this.packet_.lookup(proto.ref);
2531
 
}
 
2537
};
2532
2538
 
2533
2539
 
2534
2540
/**
2537
2543
 */
2538
2544
ProtocolValue.prototype.propertyCount = function() {
2539
2545
  return this.value_.properties ? this.value_.properties.length : 0;
2540
 
}
 
2546
};
2541
2547
 
2542
2548
 
2543
2549
/**
2547
2553
ProtocolValue.prototype.propertyName = function(index) {
2548
2554
  var property = this.value_.properties[index];
2549
2555
  return property.name;
2550
 
}
 
2556
};
2551
2557
 
2552
2558
 
2553
2559
/**
2562
2568
    }
2563
2569
  }
2564
2570
  return null;
2565
 
}
 
2571
};
2566
2572
 
2567
2573
 
2568
2574
/**
2572
2578
ProtocolValue.prototype.propertyValue = function(index) {
2573
2579
  var property = this.value_.properties[index];
2574
2580
  return this.packet_.lookup(property.ref);
2575
 
}
 
2581
};
2576
2582
 
2577
2583
 
2578
2584
/**
2581
2587
 */
2582
2588
ProtocolValue.prototype.value = function() {
2583
2589
  return this.value_.value;
2584
 
}
 
2590
};
2585
2591
 
2586
2592
 
2587
2593
ProtocolValue.prototype.valueString = function() {
2588
2594
  return this.value_.text;
2589
 
}
 
2595
};
2590
2596
 
2591
2597
 
2592
2598
function ProtocolReference(handle) {
2596
2602
 
2597
2603
ProtocolReference.prototype.handle = function() {
2598
2604
  return this.handle_;
2599
 
}
 
2605
};
2600
2606
 
2601
2607
 
2602
2608
function MakeJSONPair_(name, value) {
2626
2632
 
2627
2633
// Mapping of some control characters to avoid the \uXXXX syntax for most
2628
2634
// commonly used control cahracters.
2629
 
const ctrlCharMap_ = {
 
2635
var ctrlCharMap_ = {
2630
2636
  '\b': '\\b',
2631
2637
  '\t': '\\t',
2632
2638
  '\n': '\\n',
2638
2644
 
2639
2645
 
2640
2646
// Regular expression testing for ", \ and control characters (0x00 - 0x1F).
2641
 
const ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]');
 
2647
var ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]');
2642
2648
 
2643
2649
 
2644
2650
// Regular expression matching ", \ and control characters (0x00 - 0x1F)
2645
2651
// globally.
2646
 
const ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g');
 
2652
var ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g');
2647
2653
 
2648
2654
 
2649
2655
/**
2667
2673
        // Convert control character to unicode escape sequence.
2668
2674
        return '\\u00' +
2669
2675
          '0' + // TODO %NumberToRadixString(Math.floor(mapped / 16), 16) +
2670
 
          '0' // TODO %NumberToRadixString(mapped % 16, 16);
 
2676
          '0'; // TODO %NumberToRadixString(mapped % 16, 16)
2671
2677
      })
2672
2678
    + '"';
2673
2679
  }
2685
2691
 * @return {string} JSON formatted Date value
2686
2692
 */
2687
2693
function DateToISO8601_(value) {
2688
 
  function f(n) {
 
2694
  var f = function(n) {
2689
2695
    return n < 10 ? '0' + n : n;
2690
 
  }
2691
 
  function g(n) {
 
2696
  };
 
2697
  var g = function(n) {
2692
2698
    return n < 10 ? '00' + n : n < 100 ? '0' + n : n;
2693
 
  }
 
2699
  };
2694
2700
  return builtins.GetUTCFullYearFrom(value)         + '-' +
2695
2701
          f(builtins.GetUTCMonthFrom(value) + 1)    + '-' +
2696
2702
          f(builtins.GetUTCDateFrom(value))         + 'T' +
2738
2744
          if (property_value === null) {
2739
2745
            property_value_json = 'null';
2740
2746
          } else if (typeof property_value.toJSONProtocol == 'function') {
2741
 
            property_value_json = property_value.toJSONProtocol(true)
 
2747
            property_value_json = property_value.toJSONProtocol(true);
2742
2748
          } else if (property_value.constructor.name == 'Array'){
2743
2749
            property_value_json = SimpleArrayToJSON_(property_value);
2744
2750
          } else {
2789
2795
    }
2790
2796
    var elem = array[i];
2791
2797
    if (elem.toJSONProtocol) {
2792
 
      json += elem.toJSONProtocol(true)
 
2798
      json += elem.toJSONProtocol(true);
2793
2799
    } else if (typeof(elem) === 'object')  {
2794
2800
      json += SimpleObjectToJSON_(elem);
2795
2801
    } else if (typeof(elem) === 'boolean')  {