@@ -365,13 +365,11 @@ void ContextifyContext::CreatePerIsolateProperties(
365
365
IsolateData* isolate_data, Local<ObjectTemplate> target) {
366
366
Isolate* isolate = isolate_data->isolate ();
367
367
SetMethod (isolate, target, " makeContext" , MakeContext);
368
- SetMethod (isolate, target, " compileFunction" , CompileFunction);
369
368
}
370
369
371
370
void ContextifyContext::RegisterExternalReferences (
372
371
ExternalReferenceRegistry* registry) {
373
372
registry->Register (MakeContext);
374
- registry->Register (CompileFunction);
375
373
registry->Register (PropertyQueryCallback);
376
374
registry->Register (PropertyGetterCallback);
377
375
registry->Register (PropertySetterCallback);
@@ -1163,22 +1161,6 @@ Maybe<void> StoreCodeCacheResult(
1163
1161
return JustVoid ();
1164
1162
}
1165
1163
1166
- // TODO(RaisinTen): Reuse in ContextifyContext::CompileFunction().
1167
- MaybeLocal<Function> CompileFunction (Local<Context> context,
1168
- Local<String> filename,
1169
- Local<String> content,
1170
- LocalVector<String>* parameters) {
1171
- ScriptOrigin script_origin (filename, 0 , 0 , true );
1172
- ScriptCompiler::Source script_source (content, script_origin);
1173
-
1174
- return ScriptCompiler::CompileFunction (context,
1175
- &script_source,
1176
- parameters->size (),
1177
- parameters->data (),
1178
- 0 ,
1179
- nullptr );
1180
- }
1181
-
1182
1164
bool ContextifyScript::InstanceOf (Environment* env,
1183
1165
const Local<Value>& value) {
1184
1166
return !value.IsEmpty () &&
@@ -1392,7 +1374,19 @@ ContextifyScript::ContextifyScript(Environment* env, Local<Object> object) {
1392
1374
1393
1375
ContextifyScript::~ContextifyScript () {}
1394
1376
1395
- void ContextifyContext::CompileFunction (
1377
+ void ContextifyFunction::RegisterExternalReferences (
1378
+ ExternalReferenceRegistry* registry) {
1379
+ registry->Register (CompileFunction);
1380
+ }
1381
+
1382
+ void ContextifyFunction::CreatePerIsolateProperties (
1383
+ IsolateData* isolate_data, Local<ObjectTemplate> target) {
1384
+ Isolate* isolate = isolate_data->isolate ();
1385
+
1386
+ SetMethod (isolate, target, " compileFunction" , CompileFunction);
1387
+ }
1388
+
1389
+ void ContextifyFunction::CompileFunction (
1396
1390
const FunctionCallbackInfo<Value>& args) {
1397
1391
Environment* env = Environment::GetCurrent (args);
1398
1392
Isolate* isolate = env->isolate ();
@@ -1511,24 +1505,22 @@ void ContextifyContext::CompileFunction(
1511
1505
}
1512
1506
1513
1507
TryCatchScope try_catch (env);
1514
- Local<Object> result = CompileFunctionAndCacheResult (env,
1515
- parsing_context,
1516
- &source,
1517
- params,
1518
- context_extensions,
1519
- options,
1520
- produce_cached_data,
1521
- id_symbol,
1522
- try_catch);
1523
-
1524
- if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
1508
+ MaybeLocal<Object> maybe_result =
1509
+ CompileFunctionAndCacheResult (env,
1510
+ parsing_context,
1511
+ &source,
1512
+ params,
1513
+ context_extensions,
1514
+ options,
1515
+ produce_cached_data,
1516
+ id_symbol,
1517
+ try_catch);
1518
+ Local<Object> result;
1519
+ if (!maybe_result.ToLocal (&result)) {
1520
+ CHECK (try_catch.HasCaught ());
1525
1521
try_catch.ReThrow ();
1526
1522
return ;
1527
1523
}
1528
-
1529
- if (result.IsEmpty ()) {
1530
- return ;
1531
- }
1532
1524
args.GetReturnValue ().Set (result);
1533
1525
}
1534
1526
@@ -1544,7 +1536,7 @@ static LocalVector<String> GetCJSParameters(IsolateData* data) {
1544
1536
return result;
1545
1537
}
1546
1538
1547
- Local <Object> ContextifyContext ::CompileFunctionAndCacheResult (
1539
+ MaybeLocal <Object> ContextifyFunction ::CompileFunctionAndCacheResult (
1548
1540
Environment* env,
1549
1541
Local<Context> parsing_context,
1550
1542
ScriptCompiler::Source* source,
@@ -1566,28 +1558,29 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
1566
1558
1567
1559
Local<Function> fn;
1568
1560
if (!maybe_fn.ToLocal (&fn)) {
1569
- if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
1561
+ CHECK (try_catch.HasCaught ());
1562
+ if (!try_catch.HasTerminated ()) {
1570
1563
errors::DecorateErrorStack (env, try_catch);
1571
- return Object::New (env->isolate ());
1572
1564
}
1565
+ return {};
1573
1566
}
1574
1567
1575
1568
Local<Context> context = env->context ();
1576
1569
if (fn->SetPrivate (context, env->host_defined_option_symbol (), id_symbol)
1577
1570
.IsNothing ()) {
1578
- return Object::New (env-> isolate ()) ;
1571
+ return {} ;
1579
1572
}
1580
1573
1581
1574
Isolate* isolate = env->isolate ();
1582
1575
Local<Object> result = Object::New (isolate);
1583
1576
if (result->Set (parsing_context, env->function_string (), fn).IsNothing ())
1584
- return Object::New (env-> isolate ()) ;
1577
+ return {} ;
1585
1578
if (result
1586
1579
->Set (parsing_context,
1587
1580
env->source_map_url_string (),
1588
1581
fn->GetScriptOrigin ().SourceMapUrl ())
1589
1582
.IsNothing ())
1590
- return Object::New (env-> isolate ()) ;
1583
+ return {} ;
1591
1584
1592
1585
std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
1593
1586
if (produce_cached_data) {
@@ -1600,7 +1593,7 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
1600
1593
produce_cached_data,
1601
1594
std::move (new_cached_data))
1602
1595
.IsNothing ()) {
1603
- return Object::New (env-> isolate ()) ;
1596
+ return {} ;
1604
1597
}
1605
1598
1606
1599
return result;
@@ -1974,6 +1967,7 @@ void CreatePerIsolateProperties(IsolateData* isolate_data,
1974
1967
1975
1968
ContextifyContext::CreatePerIsolateProperties (isolate_data, target);
1976
1969
ContextifyScript::CreatePerIsolateProperties (isolate_data, target);
1970
+ ContextifyFunction::CreatePerIsolateProperties (isolate_data, target);
1977
1971
1978
1972
SetMethod (isolate, target, " startSigintWatchdog" , StartSigintWatchdog);
1979
1973
SetMethod (isolate, target, " stopSigintWatchdog" , StopSigintWatchdog);
@@ -2026,6 +2020,7 @@ static void CreatePerContextProperties(Local<Object> target,
2026
2020
void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
2027
2021
ContextifyContext::RegisterExternalReferences (registry);
2028
2022
ContextifyScript::RegisterExternalReferences (registry);
2023
+ ContextifyFunction::RegisterExternalReferences (registry);
2029
2024
2030
2025
registry->Register (CompileFunctionForCJSLoader);
2031
2026
registry->Register (StartSigintWatchdog);
0 commit comments