FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScript/DocumentInfo.cs at master · ExtrieveTechnologies/ClearScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ExtrieveTechnologies
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScript
/
DocumentInfo.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
147 lines (129 loc) · 5.08 KB
Breadcrumbs
ClearScript
/
ClearScript
/
DocumentInfo.cs
Copy path
File metadata and controls
147 lines (129 loc) · 5.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
IO
;
using
System
.
Threading
;
using
Microsoft
.
ClearScript
.
JavaScript
;
using
Microsoft
.
ClearScript
.
Util
;
namespace
Microsoft
.
ClearScript
{
/// <summary>
/// Contains meta-information for a document.
/// </summary>
public
struct
DocumentInfo
{
private
static
long
lastUniqueId
;
private
readonly
string
name
;
private
readonly
Uri
uri
;
private
DocumentCategory
category
;
private
ulong
uniqueId
;
/// <summary>
/// Initializes a new <see cref="DocumentInfo"/> structure with the specified document name.
/// </summary>
/// <param name="name">The document name.</param>
public
DocumentInfo
(
string
name
)
:
this
(
)
{
this
.
name
=
name
;
uniqueId
=
Interlocked
.
Increment
(
ref
lastUniqueId
)
.
ToUnsigned
(
)
;
}
/// <summary>
/// Initializes a new <see cref="DocumentInfo"/> structure with the specified document URI.
/// </summary>
/// <param name="uri">The document URI.</param>
public
DocumentInfo
(
Uri
uri
)
:
this
(
)
{
MiscHelpers
.
VerifyNonNullArgument
(
uri
,
"uri"
)
;
this
.
uri
=
uri
.
IsAbsoluteUri
?
uri
:
new
Uri
(
Directory
.
GetCurrentDirectory
(
)
+
Path
.
DirectorySeparatorChar
+
uri
)
;
name
=
Path
.
GetFileName
(
this
.
uri
.
AbsolutePath
)
;
uniqueId
=
Interlocked
.
Increment
(
ref
lastUniqueId
)
.
ToUnsigned
(
)
;
}
/// <summary>
/// Gets the document's name.
/// </summary>
/// <remarks>
/// This property always returns a non-blank string. If a null or blank document name was
/// specified at instantiation time, this property returns a default document name.
/// </remarks>
public
string
Name
{
get
{
return
MiscHelpers
.
EnsureNonBlank
(
name
,
Category
.
DefaultName
)
;
}
}
/// <summary>
/// Gets the document's URI.
/// </summary>
/// <remarks>
/// This property returns <c>null</c> if a URI was not specified at instantiation time.
/// </remarks>
public
Uri
Uri
{
get
{
return
uri
;
}
}
/// <summary>
/// Gets or sets an optional source map URI for the document.
/// </summary>
public
Uri
SourceMapUri
{
get
;
set
;
}
/// <summary>
/// Gets or sets the document's category.
/// </summary>
public
DocumentCategory
Category
{
get
{
return
category
??
DocumentCategory
.
Script
;
}
set
{
category
=
value
;
}
}
/// <summary>
/// Gets or sets optional document attributes.
/// </summary>
public
DocumentFlags
?
Flags
{
get
;
set
;
}
/// <summary>
/// Gets or sets an optional context callback for the document.
/// </summary>
/// <remarks>
/// <para>
/// This property currently applies only to modules. If specified, the callback is invoked
/// the first time the module attempts to retrieve its context information. The properties
/// it returns are made available to the module implementation. This mechanism can be used
/// to expose host resources selectively, securely, and without polluting the script
/// engine's global namespace.
/// </para>
/// <para>
/// Use
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta">import.meta</see></c>
/// to access the context information of a <see cref="ModuleCategory.Standard"/> JavaScript
/// module. In a <see cref="ModuleCategory.CommonJS"/> module, use <c>module.meta</c>.
/// </para>
/// </remarks>
public
DocumentContextCallback
ContextCallback
{
get
;
set
;
}
internal
UniqueDocumentInfo
MakeUnique
(
ScriptEngine
engine
)
{
return
MakeUnique
(
engine
.
DocumentNameManager
)
;
}
internal
UniqueDocumentInfo
MakeUnique
(
ScriptEngine
engine
,
DocumentFlags
?
defaultFlags
)
{
return
MakeUnique
(
engine
.
DocumentNameManager
,
defaultFlags
)
;
}
internal
UniqueDocumentInfo
MakeUnique
(
IUniqueNameManager
manager
)
{
return
MakeUnique
(
manager
,
null
)
;
}
internal
UniqueDocumentInfo
MakeUnique
(
IUniqueNameManager
manager
,
DocumentFlags
?
defaultFlags
)
{
var
info
=
this
;
if
(
!
info
.
Flags
.
HasValue
&&
defaultFlags
.
HasValue
)
{
info
.
Flags
=
defaultFlags
;
}
if
(
uniqueId
<
1
)
{
uniqueId
=
Interlocked
.
Increment
(
ref
lastUniqueId
)
.
ToUnsigned
(
)
;
}
var
uniqueName
=
manager
.
GetUniqueName
(
Name
,
Category
.
DefaultName
)
;
if
(
info
.
Flags
.
GetValueOrDefault
(
)
.
HasFlag
(
DocumentFlags
.
IsTransient
)
)
{
uniqueName
+=
" [temp]"
;
}
return
new
UniqueDocumentInfo
(
info
,
uniqueId
,
uniqueName
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL