Home | History | Annotate | Download | only in js
      1 // Copyright 2012 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // -------------------------------------------------------------------
      6 
      7 (function(global, utils) {
      8 
      9 %CheckIsBootstrapping();
     10 
     11 // -------------------------------------------------------------------
     12 // Imports
     13 
     14 var Script = utils.ImportNow("Script");
     15 
     16 // -------------------------------------------------------------------
     17 // Script
     18 
     19 /**
     20  * Set up the Script function and constructor.
     21  */
     22 %FunctionSetInstanceClassName(Script, 'Script');
     23 %AddNamedProperty(Script.prototype, 'constructor', Script,
     24                   DONT_ENUM | DONT_DELETE | READ_ONLY);
     25 
     26 
     27 /**
     28  * Get information on a specific source position.
     29  * Returns an object with the following following properties:
     30  *   script     : script object for the source
     31  *   line       : source line number
     32  *   column     : source column within the line
     33  *   position   : position within the source
     34  *   sourceText : a string containing the current line
     35  * @param {number} position The source position
     36  * @param {boolean} include_resource_offset Set to true to have the resource
     37  *     offset added to the location
     38  * @return If line is negative or not in the source null is returned.
     39  */
     40 function ScriptLocationFromPosition(position,
     41                                     include_resource_offset) {
     42   return %ScriptPositionInfo(this, position, !!include_resource_offset);
     43 }
     44 
     45 
     46 /**
     47  * If sourceURL comment is available returns sourceURL comment contents.
     48  * Otherwise, script name is returned. See
     49  * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
     50  * and Source Map Revision 3 proposal for details on using //# sourceURL and
     51  * deprecated //@ sourceURL comment to identify scripts that don't have name.
     52  *
     53  * @return {?string} script name if present, value for //# sourceURL comment or
     54  * deprecated //@ sourceURL comment otherwise.
     55  */
     56 function ScriptNameOrSourceURL() {
     57   // Keep in sync with Script::GetNameOrSourceURL.
     58   if (this.source_url) return this.source_url;
     59   return this.name;
     60 }
     61 
     62 
     63 utils.SetUpLockedPrototype(Script, [
     64     "source",
     65     "name",
     66     "source_url",
     67     "source_mapping_url",
     68     "line_offset",
     69     "column_offset"
     70   ], [
     71     "locationFromPosition", ScriptLocationFromPosition,
     72     "nameOrSourceURL", ScriptNameOrSourceURL,
     73   ]
     74 );
     75 
     76 });
     77